home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Tele / C / Comet2.1.3.cpt / Comet / dialog.c < prev    next >
Text File  |  1991-10-22  |  68KB  |  2,867 lines

  1. /*
  2.     Copyright Cornell University 1986.  All rights are reserved.
  3.     
  4.     menu.c contains routines which create, maintain, and allow access to 
  5.     items in the Macintosh menus.
  6. */
  7.  
  8. #include     <em.h>
  9.  
  10. #include    <3270.h>
  11. #include    <rcodes.h>
  12. #include    <h19.h>
  13.  
  14. #include     <h19.h>
  15. #include     <util.h>
  16. #include     <macdefs.h>
  17. #include     <resdefs.h>
  18. #include     <cntldefs.h>
  19. #include     <config.h>
  20. #include    "menudefs.h"
  21.  
  22. #include <net.h>            /* merged TCP */
  23. #ifdef DUALTCP
  24. #endif
  25.  
  26. #ifndef MACTCP
  27. #include    <tcp.h>
  28. #include    <tcpdefs.h>
  29. #endif
  30.  
  31. extern char *malloc();
  32. extern Boolean alfilter();
  33. extern short modaldialog;
  34.  
  35. char * keyswerr = "Can't update keypad switch in global configuration";
  36.  
  37.  
  38. #define OKB            1        /* OK button */
  39. #define CANB        2        /* cancel button */
  40.  
  41. #define STOPICON    2            /* Apple Alert Icon */
  42.  
  43. Handle iconh;
  44. Rect iconrect;
  45. Rect okrect;
  46.  
  47. /* we need to get inside the ModalDialog event loop to guarantee cycles for tasks--hence, */
  48.  
  49. pascal Boolean
  50. alfilter(dptr, devt, item)
  51. DialogPtr dptr;
  52. EventRecord * devt;
  53. int * item;
  54. {
  55.     char thechar;
  56.  
  57.     if (devt->what == keyDown) {
  58.         thechar = devt->message & 0xff;
  59.         if (thechar == CR || thechar == 0x03) {
  60.             *item = 1;    /* default down on CR or Enter */
  61.             return(TRUE);
  62.         }
  63.         if (devt->modifiers & cmdKey) {
  64.             /* do Cancel */
  65.             char thechar;
  66.             
  67.             thechar = devt->message & 0xff;
  68.             switch (thechar) {
  69.                 case 'x': {
  70.                     DlgCut(dptr);
  71.                     *item = 0;    
  72.                     return(TRUE);
  73.                 }
  74.                 case 'c': {
  75.                     DlgCopy(dptr);
  76.                     *item = 0;    
  77.                     return(TRUE);
  78.                 }
  79.                 case 'v': {
  80.                     DlgPaste(dptr);
  81.                     *item = 0;    
  82.                     return(TRUE);
  83.                 }
  84.                 case '.': {
  85.                     /* Command-. is a Cancel */
  86.                     *item = CANB;    
  87.                     return(TRUE);
  88.                 }
  89.             }
  90.         }
  91.     }
  92.     else if (devt->what == activateEvt && devt->message == dptr) {
  93.         GrafPtr oldport;
  94.  
  95.         if (myEvent.modifiers & activeFlag) {
  96.             GetPort(&oldport);
  97.             SetPort(dptr);
  98.     
  99.             if (okrect.top != okrect.bottom)
  100.                 buthilite(&okrect);
  101.     
  102.             SetPort(oldport);
  103.         }
  104.     }
  105.     else if (devt->what == updateEvt && devt->message == dptr) {
  106.         GrafPtr oldport;
  107.  
  108.         GetPort(&oldport);
  109.         SetPort(dptr);
  110.  
  111.         if (okrect.top != okrect.bottom)
  112.             buthilite(&okrect);
  113.  
  114.         SetPort(oldport);
  115.     }
  116.     else
  117.         defaultevent(devt);
  118.         
  119. #ifdef USETASK
  120.     if (tk_cur != NULL) {
  121.         /* if tasking is on, do a yield to avoid timeout */
  122.         bkrd_service();
  123.     }
  124. #endif
  125.     
  126.     return(FALSE);
  127. }
  128.  
  129.  
  130.  
  131. pascal Boolean
  132. errorfilter(dptr, devt, item)
  133. DialogPtr dptr;
  134. EventRecord * devt;
  135. int * item;
  136. {
  137.     char thechar;
  138.     int type;
  139.     Handle hitem;
  140.     Rect rect;
  141.  
  142.     if (tk_cur != NULL) {
  143.         /* if tasking is on, do a yield to avoid timeout */
  144.         bkrd_service();
  145.     }
  146.     if (devt->what == keyDown) {
  147.         thechar = devt->message & 0xff;
  148.         if (thechar == CR || thechar == 0x03) {
  149.             *item = 1;    /* default down on CR or Enter */
  150.             return(TRUE);
  151.         }
  152.     }
  153.     else if (devt->what == activateEvt && devt->message == dptr) {
  154.         GrafPtr oldport;
  155.  
  156.         if (myEvent.modifiers & activeFlag) {
  157.             GetPort(&oldport);
  158.             SetPort(dptr);
  159.     
  160.             GetDItem(dptr, OKB, &type, &hitem, &rect);
  161.             buthilite(&rect);
  162.                 /* hilite "OK" key */
  163.             PlotIcon(&iconrect, iconh); 
  164.     
  165.             SetPort(oldport);
  166.         }
  167.     }
  168.     else if (devt->what == updateEvt && devt->message == dptr) {
  169.         GrafPtr oldport;
  170.  
  171.         GetPort(&oldport);
  172.         SetPort(dptr);
  173.  
  174.         GetDItem(dptr, OKB, &type, &hitem, &rect);
  175.         buthilite(&rect);
  176.             /* hilite "OK" key */
  177.         PlotIcon(&iconrect, iconh); 
  178.  
  179.         SetPort(oldport);
  180.     }
  181.     else
  182.         defaultevent(devt);
  183.     return(FALSE);
  184. }
  185.  
  186.  
  187. short inerror;
  188.  
  189. #define ERRTEXT    2
  190.  
  191. error(string)
  192. char * string;
  193. {
  194.     DialogPtr errdptr;
  195.     int modalstate;
  196.     int    item_id;
  197.     GrafPtr    oport;
  198.     int            type;            /* general purpose getditem vars */
  199.     Handle        hitem;
  200.     Rect        rect;
  201.     
  202.     if (inerror) {
  203.         SysBeep(5);
  204.         return(-1);
  205.     }
  206.     
  207.     modalstate = modaldialog;
  208.     
  209.     if (chkbackground())
  210.         return(-1);
  211.  
  212.     ctop(string);
  213.     
  214.     GetPort(&oport);
  215.     inerror = TRUE;
  216.  
  217.     if ((errdptr = GetNewDialog(ALERROR, NULL, (WindowPtr) (-1))) == NULL) {
  218.         ptoc(string);
  219.         inerror = FALSE;
  220.         return(-1);
  221.     }
  222.  
  223.     GetDItem(errdptr, ERRTEXT, &type, &hitem, &rect);
  224.     SetIText(hitem, string);
  225.     
  226.     emwdeactivate();
  227.     
  228.     centerwind(errdptr);
  229.     
  230.     modaldialog = TRUE;
  231.     SetCursor(&arrow);
  232.     showcursor();
  233.     SetPort(errdptr);
  234.  
  235.     iconh = GetIcon(STOPICON);
  236.     iconrect.top = 10;
  237.     iconrect.left = 20;
  238.     iconrect.bottom = 42;
  239.     iconrect.right = 52;
  240.     PlotIcon(&iconrect, iconh); 
  241.     
  242.     GetDItem(errdptr, OKB, &type, &hitem, &rect);
  243.     buthilite(&rect);
  244.         /* hilite "OK" key */
  245.  
  246.     while (1) {
  247.         ModalDialog((ProcPtr) errorfilter, &item_id);
  248.         if (item_id == OKB)
  249.             break;
  250.     }    
  251.  
  252.     SetPort(oport);
  253.     DisposDialog(errdptr);
  254.     ptoc(string);
  255.     modaldialog = modalstate;
  256.     
  257.     inerror = FALSE;
  258. }
  259.  
  260.  
  261. stoperror(string)
  262. char * string;
  263. {
  264.     error(string);
  265. }
  266.  
  267. reserror()
  268. {
  269.     if (ResError()) {
  270.         error("Resource error");
  271.         return(-1);
  272.     }
  273. }
  274.  
  275.  
  276. /* 
  277.  *  display text in a window; both are taken from resource file, with the 
  278.  *  assumption the id number is the same for both
  279.  */
  280.  
  281. helpwindow(resid, font, fontsize)
  282. int resid;
  283. int font;
  284. int fontsize;
  285. {
  286.     long length;
  287.     Handle thetext;
  288.  
  289. #ifdef USETEXTWINDOWS
  290.     if (optkeydown() && keydp != NULL && keydp->textwindow != NULL) {
  291.         /* dump into a text window */
  292.         helptextwindow(resid);
  293.         return;
  294.     }
  295. #endif
  296.  
  297.     thetext = GetResource('TEXT', (short) resid);
  298.     if (thetext == NULL)
  299.         return(-1);
  300.     HLock(thetext);
  301.     length = GetHandleSize(thetext);
  302.  
  303.     fillwindow(resid, *thetext + 4, (long) (length - 4), font, fontsize, 0L);
  304.         /* TEXT types have 4 bytes of length in them */
  305.     HUnlock(thetext);
  306. }
  307.  
  308.  
  309. /* get a window with the specified id and fill with the text */
  310.  
  311. fillwindow(resid, thetext, length, font, fontsize, waitfor)
  312. int resid;
  313. char * thetext;
  314. long length;
  315. int font;
  316. int fontsize;
  317. long waitfor;    /*KS*/
  318. {
  319.     Rect bounds;
  320.     Rect nullrect;
  321.     GrafPtr ohelpport;
  322.     int modalstate;
  323.     FontInfo  finfo;
  324.     
  325.     if (chkbackground()) {
  326.         return;
  327.     }
  328.     if (helpwind != NULL)
  329.         fillwindclose();
  330.         
  331.     GetPort(&ohelpport);
  332.  
  333.     if ( (helpwind = GetNewWindow(resid, (Ptr) NULL, (WindowPtr) (-1)) ) == NULL)
  334.         if ( (helpwind = GetNewWindow(1000 + fontsize, (Ptr) NULL, (WindowPtr) (-1)) ) == NULL)
  335.             if ( (helpwind = GetNewWindow(1000, (Ptr) NULL, (WindowPtr) (-1)) ) == NULL)
  336.                 return(-1);
  337.             
  338.     if (keydp != NULL) {
  339.         getcontext(keydp);
  340.         emwdeactivate();
  341.     }
  342.     centerwind(helpwind);
  343.     
  344.     modalstate = modaldialog;
  345.     modaldialog = TRUE;
  346.     SetCursor(&arrow);
  347.     showcursor();
  348.     SetPort(helpwind);
  349.  
  350.     TextFont(font);
  351.     TextSize(fontsize);
  352.     
  353.     GetFontInfo(&finfo);
  354.  
  355.     /* set up text edit record */
  356.     bounds.top = 6;
  357.     bounds.left = 6;
  358.     bounds.bottom = thePort->portRect.bottom;
  359.     bounds.right = thePort->portRect.right - 6;
  360.     helptehand = TENew(&bounds, &bounds);
  361.  
  362.     (*helptehand)->fontAscent = finfo.ascent + finfo.leading;
  363.     (*helptehand)->lineHeight = (*helptehand)->fontAscent + finfo.descent; 
  364.  
  365.     (*helptehand)->txFont = font;
  366.     (*helptehand)->txSize = fontsize;
  367.     nullrect.top = nullrect.left = nullrect.bottom = nullrect.right = 0;
  368.     /* TEUpdate(&nullrect, helptehand);
  369.         incorporate the info */
  370.     (*helptehand)->viewRect.bottom = 
  371.         bounds.top +
  372.         ((thePort->portRect.bottom - bounds.top) / (*helptehand)->lineHeight )
  373.             * (*helptehand)->lineHeight;
  374.         /* round height of view rect to even bit multiple of font size */
  375.  
  376.     /* insert the text */
  377.     TESetSelect( (long) 0, (long) (*helptehand)->teLength, helptehand);
  378.     TEInsert(thetext, (long) length, helptehand);
  379.  
  380.     if (waitfor == -1) {
  381.         /* exit immediately, app must do cleanup itself by calling fillwindclose() */
  382.         SetPort(ohelpport);
  383.         filltimeout = cticks + 500;    /*KS*/
  384.         modaldialog = modalstate;
  385.         return(0);
  386.     }
  387.  
  388.     filltimeout = cticks + waitfor;    /*KS*/
  389.  
  390.     /* wait till a timeout or mouseDown event occurs to exit, unless a key is hit */
  391.     while (TRUE) {
  392.         EventRecord anevent;
  393.  
  394.         if (waitfor) {
  395.             /* if a nonzero timeout has been given, check the time */
  396.             if (cticks > filltimeout)
  397.                 break;
  398.         }
  399.         if (!GetNextEvent(mDownMask, &anevent)) {
  400.             /* wait for a mousedown; don't take keystrokes off the queue */
  401.             SystemTask();                /* keep this if/until we use WaitNextEvent */
  402.             if (tk_cur != NULL) {
  403.                 /* if tasking is on, do a yield to avoid timeout */
  404.                 bkrd_service();
  405.             }
  406.             continue;        /* KS */
  407.         }
  408.         SetPort(helpwind);
  409.         /* do paging if text off bottom */
  410.         if ( ((*helptehand)->lineHeight * (*helptehand)->nLines + (*helptehand)->destRect.top )
  411.                 > (*helptehand)->viewRect.bottom ) {
  412.                 /* do a scroll when bottom of text below bottom of window */
  413.             TEScroll(0, - ((*helptehand)->viewRect.bottom - (*helptehand)->viewRect.top), helptehand);
  414.             continue;
  415.         }
  416.         else 
  417.             break;
  418.     }
  419.  
  420.     /* release */
  421.     TEDispose(helptehand);
  422.     DisposeWindow(helpwind);
  423.     helpwind = NULL;
  424.     modaldialog = modalstate;
  425. }
  426.  
  427.  
  428. /* dispose of the window created by fillwind */
  429.  
  430. fillwindclose()
  431. {
  432.     /* release */
  433.     if (helpwind != NULL) {
  434.         while (TRUE) {
  435.             /* guarantee the copyright notice stays up long enough to be seen */
  436.             if (cticks > filltimeout)
  437.                 break;
  438.         }
  439.         TEDispose(helptehand);
  440.         DisposeWindow(helpwind);
  441.         helpwind = NULL;
  442.     }
  443. }
  444.  
  445.  
  446. /* display a copyright notice; app must clean up w/ fillwindclose() */
  447.  
  448. copynotice()
  449. {
  450.     extern char copyright[];    /* in appl/copy.c */
  451.     EventRecord myEvent;
  452.  
  453.     /* eventavail will put these back on the queue, but not any event! */
  454.     EventAvail(keyDownMask, &myEvent);
  455.     EventAvail(keyDownMask, &myEvent);
  456.     EventAvail(keyDownMask, &myEvent);
  457.         /* these calls will prompt the MultiFinder to display our startup screen */
  458.     fillwindow(COPYWINDOW, copyright, (long) strlen(copyright), geneva, 12, (long) -1);
  459. }
  460.  
  461.  
  462. /* do dialog to get connection type, terminal type, & IBM 7171 key
  463.     mapping */
  464.  
  465. #define NM_TITLE    3        /* title of dialog box, name and version */
  466.  
  467. /* connection types */
  468. #define NM_CONN        5        /* conntype = the Connection Manager */
  469. #define NM_SERDA    6        /*  = serial port a */
  470. #define NM_SERDB    7        /*  = serial port b */
  471. #define NM_TCP        8        /*  = TCP */
  472. #define NM_HOSTADDRTIT    9        /*  = TCP */
  473. #define NM_CUTCP    17        /*  = Cornell's TCP */
  474.  
  475. #define NM_HOSTNAME    11        /* the hostname field */
  476. #define NM_HOSTADDR    12        /* the host address field */
  477. #define NM_IBMKEY    16        /* check box for serial IBM mode */
  478. #define NM_HELPBUT    18        /* help button */
  479.  
  480. /* terminal types */
  481. #define NM_EMAUTOMATIC    19    /* try all of them--Telnet negotiation, serial vt100 */
  482. #define NM_VT100    20
  483. #define NM_3278        21
  484. #define NM_H19        22
  485. #define NM_VT102    23
  486. #define NM_VT220    24        /* unused */
  487.  
  488.  
  489. /* we need to get inside the ModalDialog event loop to guarantee cycles for tasks--hence, */
  490.  
  491. Rect listrect;                /* the rectangle user item in which list appears */
  492.  
  493. #ifdef TCPSELECT
  494. short ipaddrvis = TRUE;            /* the IP address has not been hidden */
  495. #endif
  496.  
  497. pascal Boolean
  498. nmwindowfilter(dptr, devt, item)
  499. DialogPtr dptr;
  500. EventRecord * devt;
  501. int * item;
  502. {
  503.     union {
  504.         long l;
  505.         Point p;
  506.     } prevcell;
  507.  
  508.     bkrd_service();
  509.     if (devt->what == keyDown) {
  510.         if ((devt->message & 0xff) == CR || (devt->message & 0xff) == ETX) {
  511.             devt->what = nullEvent;    /* ignore the key */
  512.             *item = OKB;    /* default down */
  513.             return((Boolean) TRUE);
  514.         }
  515.         if (devt->modifiers & cmdKey) {
  516.             /* do Cancel */
  517.             char thechar;
  518.             
  519.             thechar = devt->message & 0xff;
  520.             switch (thechar) {
  521.                 case 'x': {
  522.                     DlgCut(dptr);
  523.                     *item = 0;    
  524.                     return(TRUE);
  525.                 }
  526.                 case 'c': {
  527.                     DlgCopy(dptr);
  528.                     *item = 0;    
  529.                     return(TRUE);
  530.                 }
  531.                 case 'v': {
  532.                     DlgPaste(dptr);
  533.                     *item = 0;    
  534.                     return(TRUE);
  535.                 }
  536.                 case '.': {
  537.                     /* Command-. is a Cancel */
  538.                     *item = CANB;    
  539.                     return(TRUE);
  540.                 }
  541.             }
  542.         }
  543. #ifdef TCPSELECT
  544.     /* it's a bitch to make tcp selections turn on and off intelligently... */
  545.         if ((devt->message & 0xff) == TAB) {
  546.             if (!ipaddrvis) {
  547.                 devt->what = nullEvent;    /* ignore the key */
  548.                 return((Boolean) FALSE);
  549.             }
  550.             
  551.         }
  552. #endif
  553.     }
  554.     else if (devt->what == activateEvt && devt->message == dptr) {
  555.         GrafPtr oldport;
  556.  
  557.         if (myEvent.modifiers & activeFlag) {
  558.             GetPort(&oldport);
  559.             SetPort(dptr);
  560.     
  561.             buthilite(&okrect);
  562.     
  563.             SetPort(oldport);
  564.         }
  565.     }
  566.     else if (devt->what == updateEvt && devt->message == dptr) {
  567.         GrafPtr oldport;
  568.  
  569.         GetPort(&oldport);
  570.         SetPort(dptr);
  571.  
  572.         /* BeginUpdate(dptr); */
  573.         buthilite(&okrect);;
  574.         /* FrameRect(&listrect);
  575.             make a box around the list */
  576.  
  577.         /* EndUpdate(dptr); */
  578.         SetPort(oldport);
  579.     }
  580.     else
  581.         defaultevent(devt);
  582.     return((Boolean) FALSE);
  583. }
  584.  
  585.  
  586.  
  587. namewindow() 
  588. {
  589.     DialogPtr         nmdptr;
  590.     Handle            hname;    /* dialog hostname handle */
  591.     Handle            haddr;    /* dialog hostaddress handle */
  592.     Handle            hibmkey;    /* dialog hostaddress handle */
  593.     Handle            haddrtit;    /* dialog hostaddress title */
  594.  
  595.     Str255        strhostname;        /* name of host as string */
  596.     Str255        strhostaddr;        /* address of host as string */
  597.     Str255        strhostaddrtit;        /* address of host title */
  598.     Handle        title;
  599.     Handle        hmyaddr;        /* dialog hostaddress handle */
  600.     Handle        hgateaddr;    /* dialog hostaddress handle */
  601.     Handle        hok;                /* ok button */
  602.     
  603.     GrafPtr        oport;
  604.     int            item_id;        /* item that was touched */
  605.     int            len;
  606.     short        count;
  607.     int            type;            /* general purpose getditem vars */
  608.     Handle        hitem;
  609.     Rect        rect;
  610.     
  611.     short        termindex;
  612.     char        odisableterm[TERMTYPEMAX];
  613.     short        tempconntype;
  614.     short        oibmkey;
  615.     short        onewconf;
  616.     short nmcutcp;                /* Cornell TCP is selected if TRUE */
  617.     short firstterm = FALSE;
  618.     
  619.     /* else launched direct from application or no host name exists, do the dialog */
  620.     if (chkbackground())
  621.         return(-1);
  622.  
  623.     GetPort(&oport);
  624.     emwdeactivate();
  625.     
  626.     if ((nmdptr = GetNewDialog(DNEWWIND, NULL, (WindowPtr) (-1))) == NULL)
  627.         return(-1);
  628.  
  629.     centerwind(nmdptr);
  630.     
  631.     modaldialog = TRUE;
  632.     SetCursor(&arrow);
  633.     
  634.     showcursor();
  635.     
  636.     SetPort(nmdptr);
  637.  
  638.     /* save the state of things we modify in case we Cancel */
  639.     for (count = 0; count < TERMTYPECOUNT; count++) {
  640.         odisableterm[count] = emdp->disableterm[count];
  641.     }
  642.     tempconntype = emdp->conntype;
  643.     oibmkey = emdp->ibm_keymode;
  644.  
  645.  
  646.     GetDItem(nmdptr, OKB, &type, &hitem, &okrect);
  647.     buthilite(&okrect);
  648.     
  649.     /* window name */
  650.     GetDItem(nmdptr, NM_HOSTNAME, &type, &hname, &rect);
  651.     if (emdp->hhostname) {
  652.         /* paste the name in */
  653.         HLock(emdp->hhostname);
  654.         SetIText(hname, *emdp->hhostname);
  655.         HUnlock(emdp->hhostname);
  656.     }
  657.  
  658.     /* IP host address if any */
  659.     GetDItem(nmdptr, NM_HOSTADDR, &type, &haddr, &rect);
  660.     if (emdp->hlasthost) {
  661.         /* paste the address in */
  662.         HLock(emdp->hlasthost);
  663.         ctop(*emdp->hlasthost);
  664.         SetIText(haddr, *emdp->hlasthost);
  665.         ptoc(*emdp->hlasthost);
  666.         HUnlock(emdp->hlasthost);
  667.     }
  668.  
  669.     GetDItem(nmdptr, NM_HOSTADDRTIT, &type, &haddrtit, &rect);
  670.     
  671.     /* ibm key interpretation mode for ASCII 7171 access */
  672.     GetDItem(nmdptr, NM_IBMKEY, &type, &hibmkey, &rect);
  673.     if (emdp->ibm_keymode)
  674.         SetCtlValue(hibmkey, 1);
  675.  
  676.     /* disable the Conn Mgr option until it works */
  677.     GetDItem(nmdptr, NM_CONN, &type, &hitem, &rect);
  678.     HiliteControl(hitem, 255);
  679.     
  680.     /* Select the Name Text "Untitled" or whatever */
  681.     SelIText(nmdptr, NM_HOSTNAME, 0, 1000);
  682.  
  683.  
  684. #ifdef DUALTCP
  685.     /* show the current connection type */
  686.  
  687.     if (emdp->conntype == CONN_MACTCP) {
  688.         /* show MacTCP enabled */
  689.         GetDItem(nmdptr, NM_CUTCP, &type, &hitem, &rect);
  690.         SetCtlValue(hitem, 1);
  691.         nmcutcp = FALSE;
  692.     }
  693.     else {
  694.         if (emdp->conntype == CONN_CUTCP) {
  695.             /* fake it */
  696.             tempconntype = CONN_MACTCP;
  697.         }
  698.         nmcutcp = TRUE;
  699.     }
  700. #else
  701.     if (emdp->conntype == CONN_CUTCP) {
  702.         /* force it */
  703.         emdp->conntype = CONN_MACTCP;
  704.         tempconntype = CONN_MACTCP;
  705.     }
  706.     nmcutcp = FALSE;
  707.  
  708.     /* hide MacTCP control, since we always use macTCP */
  709.     GetDItem(nmdptr, NM_CUTCP, &type, &hitem, &rect);
  710.     HideControl(hitem);
  711.     GetDItem(nmdptr, NM_TCP, &type, &hitem, &rect);
  712.     SetCTitle(hitem, "\PMacTCP Telnet");
  713.  
  714. #endif
  715.     
  716.     /* show the current connection type */
  717.     if (emdp->conntype == CONN_MACTCP || emdp->conntype == CONN_CUTCP) {
  718.         GetDItem(nmdptr, NM_TCP, &type, &hitem, &rect);
  719.         SetCtlValue(hitem, 1);
  720.         nmsettcp(nmdptr, TRUE);
  721.     }
  722.     else if (emdp->conntype == CONN_SERD) {
  723.         GetDItem(nmdptr, emdp->usebport ? NM_SERDB : NM_SERDA, &type, &hitem, &rect);
  724.         SetCtlValue(hitem, 1);
  725.         nmsettcp(nmdptr, FALSE);
  726.     }
  727.     else if (emdp->conntype == CONN_COMMMGR) {
  728.         GetDItem(nmdptr, NM_CONN, &type, &hitem, &rect);
  729.         SetCtlValue(hitem, 1);
  730.         nmsettcp(nmdptr, FALSE);
  731.     }
  732.     
  733.     /* show the current terminal types; auto will have ALL FALSE */
  734.     /* the logic could be a little simpler, but the original interface allowed
  735.         selecting arbitrary lists of enabled terminals rather than 
  736.         auto or just one... */
  737.         
  738.     for (count = 0, termindex = NM_VT100; count < TERMTYPECOUNT; 
  739.             count++, termindex++) {
  740.             
  741.             if (emdp->disableterm[count]) {
  742.                 if (firstterm)
  743.                     /* we've found one enabled & one disabled, not auto */
  744.                     break;
  745.                 else
  746.                     /* try to find an enabled terminal */
  747.                     continue;
  748.             }
  749.             else {
  750.                 if (!firstterm) {
  751.                     /* remember the first terminal we find enabled in case
  752.                         they aren't ALL enabled... */
  753.                     firstterm = termindex;
  754.                     if (count == (TERMTYPECOUNT - 1) ) {
  755.                         /* last terminal in the list, make sure count < TERMTYPECOUNT */
  756.                         break;
  757.                     }
  758.                 }
  759.         }
  760.     }
  761.     if (count >= TERMTYPECOUNT) {
  762.         /* all or none were selected, select the terminal type automatically */
  763.         GetDItem(nmdptr, NM_EMAUTOMATIC, &type, &hitem, &rect);
  764.     }
  765.     else {
  766.         GetDItem(nmdptr, firstterm, &type, &hitem, &rect);
  767.     }
  768.     /* set the terminal type radio button on */
  769.     SetCtlValue(hitem, 1);
  770.     
  771.     TEFromScrap();
  772.  
  773.     while (1)
  774.     {
  775.         ModalDialog((ProcPtr) nmwindowfilter, &item_id);
  776.         termindex = item_id - NM_VT100;
  777.         switch (item_id)
  778.         {
  779.             case OKB: {
  780.                 for (count = 0; count < TERMTYPECOUNT; count++) {
  781.                     if (!emdp->disableterm[count])
  782.                         break;
  783.                 }
  784.                 if (count == TERMTYPECOUNT) {
  785.                     error("Sorry, but you must enable at least one terminal type!");
  786.                     buthilite(&okrect);
  787.                     break;
  788.                 }
  789.  
  790.                 GetIText(hname, &strhostname);
  791.                 
  792.                 if (tempconntype == CONN_MACTCP) {
  793.                     /* discriminate between the TCPs */
  794.                     if (nmcutcp)
  795.                         emdp->conntype = CONN_CUTCP;
  796.                     else
  797.                         emdp->conntype = CONN_MACTCP;
  798.                 }
  799.                 else
  800.                     emdp->conntype = tempconntype;
  801.                     
  802.                 if (macipopen 
  803.                         && tempconntype != CONN_MACTCP 
  804.                         && emdp->tcp_stream) 
  805.                 {
  806.                     /* MacTCP was open for this window */
  807.                     if (emdp->connopen) {
  808.     error("You need to close the open session before switching from MacTCP");
  809.                         break;
  810.                     }
  811.                     else {
  812.                         /* release MacTCP memory */
  813.                         tcp_release(emdp);
  814.                         tcpmemoryreclaim(emdp);
  815.                     }
  816.                 }
  817.  
  818.                 /* check to see whether the TCP package used should change */
  819.                 if (macipopen) {
  820.                     if (emdp->conntype == CONN_CUTCP) {
  821.                         error("Opening session using MacTCP, which is already running");
  822.                         emdp->conntype = CONN_MACTCP;
  823.                     }
  824.                 }
  825.                 else if (cutcpopen) {
  826.                     if (emdp->conntype == CONN_MACTCP) {
  827.                         error("Opening session using Cornell TCP, which is already running");
  828.                         emdp->conntype = CONN_CUTCP;
  829.                     }
  830.                 }
  831.                 
  832.                 if (emdp->conntype == CONN_MACTCP
  833.                         || emdp->conntype == CONN_CUTCP) {
  834.                     /* use the host name entry */
  835.                     GetIText(haddr, &strhostaddr);
  836.                     len = strhostaddr.length + 1;
  837.                     ptoc(&strhostaddr);
  838.                     
  839.                     GetIText(haddrtit, &strhostaddrtit);
  840.                     SetIText(haddrtit, "\PResolving...");
  841.                     
  842.                     if (resolve_name(&strhostaddr, &emdp->fhost)) {
  843.                         /* error occurred, the title to "Host address" */
  844.                         SetIText(haddrtit, &strhostaddrtit);
  845.                         break;
  846.                     }
  847.  
  848.                     if (emdp->hlasthost) {
  849.                         DisposHandle(emdp->hlasthost);
  850.                         emdp->hlasthost = NULL;
  851.                     }
  852.                     PtrToHand(&strhostaddr, &emdp->hlasthost, (long) len);
  853.                         /* save address as c string in emdp->hlasthost */
  854.  
  855.                 }
  856.             
  857.                 len = strhostname.length + 1;
  858.                 if (emdp->hhostname) {
  859.                     DisposHandle(emdp->hhostname);
  860.                     emdp->hhostname = NULL;
  861.                 }
  862.                 PtrToHand(&strhostname, &emdp->hhostname, (long) len);
  863.                     /* save name as pascal string in emdp->hhostname */
  864.                 setappfilename();
  865.                     /* reset the default document file name */
  866.  
  867.                 if (emdp->emwindow) {
  868.                     /* update the window title if a window exists */
  869.                     HLock(emdp->hhostname);
  870.                     windowtitle(emdp, *emdp->hhostname);
  871.                     HUnlock(emdp->hhostname);
  872.                     windmenutitle(emdp);
  873.                 }
  874.                 ZeroScrap();
  875.                 TEToScrap();
  876.                     /* copy the TE scrap to the Scrap */
  877.  
  878.                 DisposDialog(nmdptr);
  879.                 SetPort(oport);
  880.                 modaldialog = FALSE;
  881.                 
  882.                 okrect.top = okrect.left = okrect.bottom = okrect.right = 0;
  883.                 return(0);
  884.             }
  885.             case CANB: {
  886.                 /* restore the old settings */
  887.                 for (count = 0; count < TERMTYPECOUNT; count++) {
  888.                     emdp->disableterm[count] = odisableterm[count];
  889.                 }
  890.                 emdp->ibm_keymode = oibmkey;
  891.                 emdp->confchanged = FALSE;
  892.                 emdp->newconf = onewconf;
  893.  
  894.                 ZeroScrap();
  895.                 TEToScrap();
  896.                     /* copy the TE scrap to the Scrap */
  897.  
  898.                 DisposDialog(nmdptr);
  899.                 SetPort(oport);
  900.                 modaldialog = FALSE;
  901.  
  902.                 okrect.top = okrect.left = okrect.bottom = okrect.right = 0;
  903.                 return(-1);
  904.             }
  905.             case NM_HOSTADDR: {
  906.                 emdp->confchanged = TRUE;
  907.                 break;
  908.             }
  909.             case NM_HOSTNAME: {
  910.                 emdp->confchanged = TRUE;
  911.                 emdp->newconf = TRUE;
  912.                 break;
  913.             }
  914.             /* connection types -- 4 radio buttons */
  915.             case NM_CONN: {
  916.                 nmdialbutset(nmdptr, item_id);
  917.                 nmsettcp(nmdptr, FALSE);
  918.                 tempconntype = CONN_COMMMGR;
  919.                 break;
  920.             }
  921.             case NM_SERDA: {
  922.                 nmdialbutset(nmdptr, item_id);
  923.                 nmsettcp(nmdptr, FALSE);
  924.                 tempconntype = CONN_SERD;
  925.                 emdp->usebport = FALSE;
  926.                 break;
  927.             }
  928.             case NM_SERDB: {
  929.                 nmdialbutset(nmdptr, item_id);
  930.                 nmsettcp(nmdptr, FALSE);
  931.                 tempconntype = CONN_SERD;
  932.                 emdp->usebport = TRUE;
  933.                 break;
  934.             }
  935.             case NM_TCP: {
  936.                 /* select TCP */
  937.                 nmdialbutset(nmdptr, item_id);
  938.                 nmsettcp(nmdptr, TRUE);
  939.                 tempconntype = CONN_MACTCP;
  940.                 break;
  941.             }
  942. #ifdef DUALTCP
  943.             case NM_CUTCP: {
  944.                 /* switch between MacTCP & cornell */
  945.                 /* you can't change transport horses in midstream */
  946.                 if (nmcutcp) {
  947.                         nmcutcp = FALSE;
  948.                 }
  949.                 else
  950.                         nmcutcp = TRUE;
  951.  
  952.                 GetDItem(nmdptr, NM_CUTCP, &type, &hitem, &rect);
  953.                 SetCtlValue(hitem, nmcutcp ? 0 : 1);
  954.                 break;
  955.             }
  956. #endif
  957.             /* terminal types, 3 check boxes */
  958.             case NM_VT100:
  959.             case NM_VT102:
  960.             case NM_3278:
  961.             case NM_H19:
  962.             case NM_EMAUTOMATIC:
  963.             {
  964.                 nmtermbutset(nmdptr, item_id);
  965.                 break;
  966.             }            
  967.             case NM_IBMKEY: {
  968.                 /* UNUSED--now set in the Control Window dialog */
  969.                 
  970.                 emdp->ibm_keymode = !emdp->ibm_keymode;
  971.                 emdp->confchanged = TRUE;
  972.                 SetCtlValue(hibmkey, emdp->ibm_keymode ? 1 : 0);
  973.                 break;
  974.             }
  975.             case NM_HELPBUT: {
  976.                 helpwindow(TEXTLOGON, geneva, 9);
  977.                 modaldialog = TRUE;
  978.                 break;
  979.             }
  980.             default: {
  981.                 break;
  982.             }
  983.         }
  984.     }
  985. }
  986.  
  987.  
  988. /* set TCP items on or off */
  989.  
  990. nmsettcp(nmdptr, state)
  991. DialogPtr nmdptr;
  992. int state;
  993. {
  994.     Handle hitem;
  995.     short    type;
  996.     Rect rect;
  997.  
  998. #ifdef TCPSELECT
  999.     if (state == ipaddrvis) {
  1000.         /* same state as before, ignore */
  1001.         return;
  1002.     }
  1003.     else {
  1004.         ipaddrvis = state;
  1005.         
  1006.         if (ipaddrvis) {
  1007.             GetDItem(nmdptr, NM_HOSTADDR, &type, &hitem, &rect);
  1008.             SetDItem(nmdptr, NM_HOSTADDR, editText, hitem, &rect);
  1009.  
  1010.             GetDItem(nmdptr, NM_HOSTADDRTIT, &type, &hitem, &rect);
  1011.             SetDItem(nmdptr, NM_HOSTADDRTIT, statText, hitem, &rect);
  1012.  
  1013.             /* switch to the address editing field  */
  1014.             SelIText(nmdptr, NM_HOSTNAME, 0, 0);
  1015.             SelIText(nmdptr, NM_HOSTADDR, 0, 1000);
  1016.         }
  1017.         else {
  1018.             if (((DialogPeek) nmdptr)->editField == NM_HOSTADDR - 1) {
  1019.                 /* switch to the name editing field if Address is the current field */
  1020.                 SelIText(nmdptr, NM_HOSTADDR, 0, 0);
  1021.                 SelIText(nmdptr, NM_HOSTNAME, 0, 1000);
  1022.             }
  1023.             GetDItem(nmdptr, NM_HOSTADDR, &type, &hitem, &rect);
  1024.             SetDItem(nmdptr, NM_HOSTADDR, editText, hitem, &rect);
  1025.                 /*  + itemDisable, if only Dialog Manager did something useful... */
  1026.             GetDItem(nmdptr, NM_HOSTADDRTIT, &type, &hitem, &rect);
  1027.             SetDItem(nmdptr, NM_HOSTADDRTIT, statText + itemDisable, hitem, &rect);
  1028.         }
  1029.     }
  1030. #else
  1031.     /* doesn't actually disable the thing anyway... lord the dialog manager is
  1032.         useless!
  1033.     GetDItem(nmdptr, NM_HOSTADDR, &type, &hitem, &rect);
  1034.     SetDItem(nmdptr, NM_HOSTADDR, type + state, hitem, &rect);
  1035.     */
  1036.     
  1037.     GetDItem(nmdptr, NM_HOSTADDRTIT, &type, &hitem, &rect);
  1038.     SetDItem(nmdptr, NM_HOSTADDRTIT, type + state, hitem, &rect);
  1039.  
  1040. #ifdef DUALTCP
  1041.     GetDItem(nmdptr, NM_CUTCP, &type, &hitem, &rect);
  1042.     HiliteControl(hitem, state ? 0 : 255);
  1043. #endif
  1044. #endif
  1045. }
  1046.  
  1047. /* set the button selected and reset the others */
  1048.  
  1049. nmdialbutset(dlog, itemid)
  1050. DialogPtr dlog;
  1051. short itemid;
  1052. {
  1053.     short    type;
  1054.     Rect rect;
  1055.     Handle hitem;
  1056.  
  1057.     emdp->confchanged = TRUE;
  1058.  
  1059.     GetDItem(dlog, NM_CONN, &type, &hitem, &rect);
  1060.     SetCtlValue(hitem, itemid == NM_CONN ? 1 : 0);
  1061.     GetDItem(dlog, NM_SERDA, &type, &hitem, &rect);
  1062.     SetCtlValue(hitem, itemid == NM_SERDA ? 1 : 0);
  1063.     GetDItem(dlog, NM_SERDB, &type, &hitem, &rect);
  1064.     SetCtlValue(hitem, itemid == NM_SERDB ? 1 : 0);
  1065.     GetDItem(dlog, NM_TCP, &type, &hitem, &rect);
  1066.     SetCtlValue(hitem, itemid == NM_TCP ? 1 : 0);
  1067. }
  1068.  
  1069.  
  1070. /* set the button selected and reset the others;  */
  1071.  
  1072. nmtermbutset(dlog, itemid)
  1073. DialogPtr dlog;
  1074. short itemid;
  1075. {
  1076.     short    type;
  1077.     Rect rect;
  1078.     Handle hitem;
  1079.  
  1080.     emdp->confchanged = TRUE;
  1081.  
  1082.     /* set only one radio button for emulation:  auto, vt100, 3270, h19 */
  1083.     
  1084.     GetDItem(dlog, NM_EMAUTOMATIC, &type, &hitem, &rect);
  1085.     SetCtlValue(hitem, itemid == NM_EMAUTOMATIC ? 1 : 0);
  1086.     
  1087.     GetDItem(dlog, NM_VT100, &type, &hitem, &rect);
  1088.     SetCtlValue(hitem, itemid == NM_VT100 ? 1 : 0);
  1089.  
  1090.     GetDItem(dlog, NM_VT102, &type, &hitem, &rect);
  1091.     SetCtlValue(hitem, itemid == NM_VT102 ? 1 : 0);
  1092.  
  1093.     GetDItem(dlog, NM_3278, &type, &hitem, &rect);
  1094.     SetCtlValue(hitem, itemid == NM_3278 ? 1 : 0);
  1095.  
  1096.     GetDItem(dlog, NM_H19, &type, &hitem, &rect);
  1097.     SetCtlValue(hitem, itemid == NM_H19 ? 1 : 0);
  1098.  
  1099.     /* set the disableterm array accordingly */
  1100.     if (itemid == NM_EMAUTOMATIC) {
  1101.         /* enable all the terminals */
  1102.         emdp->disableterm[TERM_VT100] = FALSE;
  1103.         emdp->disableterm[TERM_VT102] = FALSE;
  1104.         emdp->disableterm[TERM_VT220] = FALSE;
  1105.         emdp->disableterm[TERM_3270] = FALSE;
  1106.         emdp->disableterm[TERM_H19] = FALSE;
  1107.     }
  1108.     else {
  1109.         /* enable only one terminal */
  1110.         emdp->disableterm[TERM_VT100] = (itemid == NM_VT100 ? FALSE : TRUE);
  1111.         emdp->disableterm[TERM_VT102] = (itemid == NM_VT102 ? FALSE : TRUE);
  1112.         emdp->disableterm[TERM_3270] = (itemid == NM_3278 ? FALSE : TRUE);
  1113.         emdp->disableterm[TERM_H19] = (itemid == NM_H19 ? FALSE : TRUE);
  1114.     }
  1115. }
  1116.  
  1117.  
  1118. /* perform a dialog to set the color map */
  1119.  
  1120. #define CM_OK    1
  1121. #define CM_CANCEL    2
  1122. #define CM_COLOR    3        /* "Color Map On" Title/Button */
  1123. #define CM_BAR        4
  1124. #define CM_CBASE    5        /* 8 * 2 check boxes filled with color */
  1125. #define CM_CEND        21        /* 8 * 2 check boxes filled with color */
  1126. #define CM_STROFF    26        /* string descriptions */
  1127. #define CM_BOX        34        /* where to draw strings */
  1128. #define CM_SESSIONNAME    35
  1129.  
  1130. char * setcolortext[] = {
  1131.     /* ASCII attribute types */
  1132.     "Normal",
  1133.     "Reverse",
  1134.     "Bold",
  1135.     "Bold Reverse",
  1136.     "Blink",
  1137.     "Blink Reverse",
  1138.     "Blink Bold",
  1139.     "Blink Bold Reverse",
  1140.     
  1141.     /* IBM field types */
  1142.     "Normal",
  1143.     "Sense",
  1144.     "Bold",
  1145.     "Invisible",
  1146.     "Protected",
  1147.     "Protected Sense",
  1148.     "Protected Bold",
  1149.     "Protected Invisible"
  1150. };
  1151. #define CM_STROFFMAX    15        /* longest string description, happens to be last */
  1152.  
  1153.  
  1154. setcolormap()
  1155. {
  1156.     DialogPtr    cmdial;
  1157.     short    item_id;
  1158.     short    type;
  1159.     Rect rect;
  1160.     Rect boxrect;
  1161.     Handle hitem;
  1162.         /* general purpose GetDItem vars */
  1163.     GrafPtr    oport;
  1164.     short count;
  1165.     short control;
  1166.     short colorindex;
  1167.     struct ibmcolormap backupmap;
  1168.     Point point;
  1169.     Handle ditlh;
  1170.     RGBColor forecolor;
  1171.     RGBColor backcolor;
  1172.     char string[255];
  1173.     char spaces[255];
  1174.     short ocolor;
  1175.     short ofont;
  1176.     short osize;
  1177.     short incount;
  1178.     char windtit[256];        /* temp for window title */
  1179.     
  1180.     if (chkbackground())
  1181.         return;
  1182.  
  1183.     GetPort(&oport);
  1184.     /* a 'dctb' resource exists, so a Color window will be allocated ... */
  1185.     if ((cmdial = GetNewDialog(DSETCOLORMAP, (Ptr) NULL, (WindowPtr) (-1))) == NULL)
  1186.         return(-1);
  1187.  
  1188.     getcontext(keydp);
  1189.     emwdeactivate();
  1190.     overwind(cmdial);        /* place over current window rather than 
  1191.         default screen to represent the colormap situation accurately */
  1192.     
  1193.     SetCursor(&arrow);
  1194.     showcursor();
  1195.     SetPort(cmdial);
  1196.  
  1197.     modaldialog = TRUE;
  1198.  
  1199.     GetDItem(cmdial, CM_BOX, &type, &hitem, &boxrect);
  1200.         /* get box for drawing examples */
  1201.         
  1202.     GetDItem(cmdial, CM_OK, &type, &hitem, &okrect);
  1203.     buthilite(&okrect);
  1204.         /* hilite "OK" key */
  1205.  
  1206.     GetDItem(cmdial, CM_SESSIONNAME, &type, &hitem, &rect);
  1207.     GetWTitle(emdp->emwindow, &windtit[0]);
  1208.     SetIText(hitem, &windtit[0]);
  1209.         /* put the session name in the window */
  1210.  
  1211.     GetDItem(cmdial, CM_COLOR, &type, &hitem, &rect);
  1212.     SetCtlValue(hitem, keydp->color ? 1 : 0);
  1213.         /* set "Color Map On" button */
  1214.         
  1215.     TextMode(srcCopy);            /* obliterate when redrawing */
  1216.     ofont = ((GrafPtr) cmdial)->txFont;
  1217.     osize = ((GrafPtr) cmdial)->txSize;
  1218.  
  1219.     /* make a pascal space string the same size as the text items */
  1220.     spaces[0] = strlen(setcolortext[CM_STROFFMAX]);
  1221.     for (count = 1; count <= spaces[0]; count++)
  1222.         spaces[count] = ' ';
  1223.     
  1224.     /* title the controls */
  1225.     for (count = 0; count < 8; count++) {
  1226.         int ibmoffset;
  1227.         
  1228.         ibmoffset = keydp->ibm_mode ? 8 : 0;
  1229.         GetDItem(cmdial, count + CM_STROFF, &type, &hitem, &rect);
  1230.  
  1231.         sprintf(&string[0], "%s", setcolortext[count + ibmoffset]);
  1232.         ctop(&string[0]);
  1233.  
  1234.         /* append spaces to the items to even out their lengths */
  1235.         for (incount = string[0] + 1; incount <= spaces[0]; incount++) {
  1236.             string[incount] = ' ';
  1237.         }
  1238.         string[0] = spaces[0];
  1239.         
  1240.         SetIText(hitem, &string[0]);
  1241.     }
  1242.  
  1243.     /* save the current array and draw the example text */
  1244.     GetForeColor(&forecolor);
  1245.     GetBackColor(&backcolor);
  1246.     backupmap = keydp->ibmcolormap;
  1247.     ocolor = keydp->color;
  1248.     
  1249.     TextFont(monaco);
  1250.     TextSize(9);
  1251.     
  1252.     /* the second check box of each pair has text describing the function... 
  1253.         draw it in WYSIWYG color */
  1254.  
  1255.     for (control = CM_CBASE, count = colorindex = 0;
  1256.             control < CM_CEND; 
  1257.             count++, control++, colorindex += 2) {
  1258.  
  1259.         GetDItem(cmdial, control++, &type, &hitem, &rect);
  1260.         RGBForeColor(&forecolor);
  1261.         FrameRect(&rect);
  1262.         InsetRect(&rect, 1, 1);
  1263.         RGBForeColor(&keydp->ibmcolormap.colors[colorindex]);
  1264.         PaintRect(&rect);
  1265.         
  1266.         GetDItem(cmdial, control, &type, &hitem, &rect);
  1267.         RGBForeColor(&forecolor);
  1268.         FrameRect(&rect);
  1269.         InsetRect(&rect, 1, 1);
  1270.         RGBForeColor(&keydp->ibmcolormap.colors[colorindex + 1]);
  1271.         PaintRect(&rect);
  1272.  
  1273.         /* draw an example if not INVIS */
  1274.         RGBForeColor(&keydp->ibmcolormap.colors[colorindex]);
  1275.         RGBBackColor(&keydp->ibmcolormap.colors[colorindex + 1]);
  1276.         MoveTo(boxrect.left, rect.top + 10);
  1277.         if (keydp->ibm_mode && (colorindex == 6 || colorindex == 14))
  1278.             /* WYSIWYG, don't draw invis text */
  1279.             DrawString(&spaces[0]);
  1280.         else {                
  1281.             GetDItem(cmdial, count + CM_STROFF, &type, &hitem, &rect);
  1282.             GetIText(hitem, &string[0]);
  1283.             DrawString(&string[0]);
  1284.         }
  1285.     }
  1286.     RGBForeColor(&forecolor);
  1287.     RGBBackColor(&backcolor);
  1288.     TextFont(ofont);
  1289.     TextSize(osize);
  1290.     
  1291.     while (TRUE) {
  1292.         ModalDialog((ProcPtr) alfilter, &item_id);
  1293.         switch (item_id) {
  1294.             case CM_CANCEL: {
  1295.                 /* restore the old settings */
  1296.                 keydp->ibmcolormap = backupmap;
  1297.                 keydp->color = ocolor;
  1298.                 /* fall through */
  1299.             }
  1300.             case CM_OK: {
  1301.                 Rect paintrect;        /* emulator area on screen */
  1302.                 
  1303.                 if (keydp->color)
  1304.                     keydp->realattr = DSPMOD;
  1305.                 else
  1306.                     keydp->realattr = DSPD;
  1307.                 
  1308.                 SetPort(keywindow);
  1309.  
  1310.                 paintrect.top = -5;
  1311.                 paintrect.left = -3;
  1312.                 paintrect.bottom = keywindow->portRect.bottom;
  1313.                 paintrect.right = keydp->h19right - 7;
  1314.     
  1315.                 if (!keydp->color)
  1316.                     EraseRect(&paintrect);
  1317.                     
  1318.                 InvalRect(&paintrect);
  1319.                 DisposDialog(cmdial);
  1320.                 SetPort(oport);
  1321.                 modaldialog = FALSE;
  1322.                 okrect.top = okrect.left = okrect.bottom = okrect.right = 0;
  1323.  
  1324.                 if (item_id == CM_CANCEL)
  1325.                     return(-1);
  1326.                 else
  1327.                     return(0);
  1328.             }
  1329.             case CM_COLOR: {
  1330.                 keydp->color = !keydp->color;
  1331.                 GetDItem(cmdial, CM_COLOR, &type, &hitem, &rect);
  1332.                 SetCtlValue(hitem, keydp->color ? 1 : 0);
  1333.                 break;
  1334.             }
  1335.             default: {
  1336.                 if (item_id >= CM_CBASE && item_id < CM_CEND) {
  1337.                     /* do a color picker dialog for the item */
  1338.                     colorindex = item_id - CM_CBASE;
  1339.                     
  1340.                     /* place the picker over the dialog */
  1341.                     point.v = ((GrafPtr) cmdial)->portRect.top + 5;
  1342.                     point.h = ((GrafPtr) cmdial)->portRect.left + 5;
  1343.                     LocalToGlobal(&point);
  1344.                     
  1345.                     GetDItem(cmdial, ((colorindex / 2) + CM_STROFF), 
  1346.                         &type, &hitem, &rect);
  1347.                     GetIText(hitem, &string[0]);
  1348.                     
  1349.                     /* bogus getcolor call pushes getcolor selector #9 on stack */
  1350.                     getcolor(pass(point), (StringPtr) &string[0], 
  1351.                         &keydp->ibmcolormap.colors[colorindex],
  1352.                         &keydp->ibmcolormap.colors[colorindex],
  1353.                         9);
  1354.                     buthilite(&okrect);
  1355.                     
  1356.                     /* redraw the example text */
  1357.                     GetForeColor(&forecolor);
  1358.                     GetBackColor(&backcolor);
  1359.                     TextFont(monaco);
  1360.                     TextSize(9);
  1361.  
  1362.                     for (control = CM_CBASE, count = colorindex = 0;
  1363.                             control < CM_CEND; 
  1364.                             count++, control++, colorindex += 2) {
  1365.                 
  1366.                         GetDItem(cmdial, control++, &type, &hitem, &rect);
  1367.                         RGBForeColor(&forecolor);
  1368.                         FrameRect(&rect);
  1369.                         InsetRect(&rect, 1, 1);
  1370.                         RGBForeColor(&keydp->ibmcolormap.colors[colorindex]);
  1371.                         PaintRect(&rect);
  1372.                         
  1373.                         GetDItem(cmdial, control, &type, &hitem, &rect);
  1374.                         RGBForeColor(&forecolor);
  1375.                         FrameRect(&rect);
  1376.                         InsetRect(&rect, 1, 1);
  1377.                         RGBForeColor(&keydp->ibmcolormap.colors[colorindex + 1]);
  1378.                         PaintRect(&rect);
  1379.                 
  1380.                         /* draw an example if not INVIS */
  1381.                         RGBForeColor(&keydp->ibmcolormap.colors[colorindex]);
  1382.                         RGBBackColor(&keydp->ibmcolormap.colors[colorindex + 1]);
  1383.                         MoveTo(boxrect.left, rect.top + 10);
  1384.                         if (keydp->ibm_mode && (colorindex == 6 || colorindex == 14))
  1385.                             /* WYSIWYG, don't draw invis text */
  1386.                             DrawString(&spaces[0]);
  1387.                         else {                
  1388.                             GetDItem(cmdial, count + CM_STROFF, &type, &hitem, &rect);
  1389.                             GetIText(hitem, &string[0]);
  1390.                             DrawString(&string[0]);
  1391.                         }
  1392.                     }
  1393.                     RGBForeColor(&forecolor);
  1394.                     RGBBackColor(&backcolor);
  1395.                     TextFont(ofont);
  1396.                     TextSize(osize);
  1397.                 }
  1398.                 break;
  1399.             }
  1400.         }
  1401.     }
  1402. }
  1403.  
  1404.  
  1405. /* perform a dialog to do Window Configuration for session items */
  1406.  
  1407. #define WC_OK            1
  1408. #define WC_CANCEL        2
  1409. #define WC_HELP            3        /* type #s must correspond to this list */
  1410. #define WC_SESSIONNAME    4
  1411.  
  1412. #define WC_TITLE    3        /* 12 types are allocated in the dialog */
  1413.  
  1414. #define WC_MFSHRINK    7
  1415. #define WC_CLOSE    8
  1416. #define WC_BLOCK    9
  1417. #define WC_BLINK    10
  1418.  
  1419. #define WC_EDITDOWNWRAP    13
  1420. #define WC_EDITUPWRAP    14
  1421.  
  1422.  
  1423. setwindconf()
  1424. {
  1425.     DialogPtr    wcdial;
  1426.     short    item_id;
  1427.     short    type;
  1428.     Rect rect;
  1429.     Handle hitem;
  1430.         /* general purpose GetDItem vars */
  1431.     GrafPtr    oport;
  1432.     short count;
  1433.     short termindex;
  1434.     char windtit[256];        /* temp for window title */
  1435.     
  1436.     /* vars we work on */
  1437.     short autoshrink;
  1438.     short disposeonclose;
  1439.     short blockcurs;
  1440.     short changecurs;
  1441.     short editupwrap;
  1442.     short editdownwrap;
  1443.     
  1444.     if (chkbackground())
  1445.         return(-1);
  1446.  
  1447.     GetPort(&oport);
  1448.     if ((wcdial = GetNewDialog(DWINDCONFIG, (Ptr) NULL, (WindowPtr) (-1))) == NULL)
  1449.         return(-1);
  1450.  
  1451.     getcontext(keydp);
  1452.     emwdeactivate();
  1453.     
  1454.     SetPort(wcdial);
  1455.     centerwind(wcdial);
  1456.  
  1457.     SetCursor(&arrow);
  1458.     showcursor();
  1459.     
  1460.     modaldialog = TRUE;
  1461.  
  1462.     GetDItem(wcdial, WC_OK, &type, &hitem, &okrect);
  1463.     buthilite(&okrect);
  1464.         /* hilite "OK" key */
  1465.  
  1466.     GetDItem(wcdial, WC_SESSIONNAME, &type, &hitem, &rect);
  1467.     GetWTitle(emdp->emwindow, &windtit[0]);
  1468.     SetIText(hitem, &windtit[0]);
  1469.         /* put the session name in the window */
  1470.  
  1471.     /* get current settings */
  1472.     autoshrink = emdp->autoshrink;
  1473.     disposeonclose = emdp->disposeonclose;
  1474.     blockcurs = emdp->blockcurs;
  1475.     changecurs = emdp->changecurs;
  1476.     editupwrap = emdp->editupwrap;
  1477.     editdownwrap = emdp->editdownwrap;
  1478.     
  1479.     /* set the controls to reflect the settings */
  1480.     GetDItem(wcdial, WC_MFSHRINK, &type, &hitem, &rect);
  1481.     SetCtlValue(hitem, autoshrink ? 1 : 0);
  1482.     GetDItem(wcdial, WC_CLOSE, &type, &hitem, &rect);
  1483.     SetCtlValue(hitem, disposeonclose ? 1 : 0);
  1484.     GetDItem(wcdial, WC_BLOCK, &type, &hitem, &rect);
  1485.     SetCtlValue(hitem, blockcurs ? 1 : 0);
  1486.     GetDItem(wcdial, WC_BLINK, &type, &hitem, &rect);
  1487.     SetCtlValue(hitem, changecurs ? 1 : 0);
  1488.  
  1489.     GetDItem(wcdial, WC_EDITUPWRAP, &type, &hitem, &rect);
  1490.     SetCtlValue(hitem, editupwrap ? 1 : 0);
  1491.     GetDItem(wcdial, WC_EDITDOWNWRAP, &type, &hitem, &rect);
  1492.     SetCtlValue(hitem, editdownwrap ? 1 : 0);
  1493.  
  1494.     while (TRUE) {
  1495.         ModalDialog((ProcPtr) alfilter, &item_id);
  1496.         termindex = item_id - 3;
  1497.         switch (item_id) {
  1498.             case WC_OK: {
  1499.                 if (blockcurs != emdp->blockcurs) {
  1500.                     SetPort(emdp->emwindow);
  1501.                     newcursor();
  1502.                     SetPort(wcdial);
  1503.                 }
  1504.                 
  1505.                 /* update the settings */
  1506.                 emdp->autoshrink = autoshrink;
  1507.                 emdp->disposeonclose = disposeonclose;
  1508.                 emdp->blockcurs = blockcurs;
  1509.                 emdp->changecurs = changecurs;
  1510.                 emdp->editupwrap = editupwrap;
  1511.                 emdp->editdownwrap = editdownwrap;
  1512.                 
  1513.                 emdp->confchanged = TRUE;
  1514.                 
  1515.             }
  1516.             case WC_CANCEL: {
  1517.                 DisposDialog(wcdial);
  1518.                 SetPort(oport);
  1519.                 modaldialog = FALSE;
  1520.  
  1521.                 okrect.top = okrect.left = okrect.bottom = okrect.right = 0;
  1522.                 if (item_id == WC_CANCEL)
  1523.                     return(-1);
  1524.                 return(0);
  1525.             }
  1526.             case WC_HELP: {
  1527.                 helpwindow(TEXTWINDDLOG, geneva, 9);
  1528.                 buthilite(&okrect);
  1529.                 break;
  1530.             }
  1531.             case WC_MFSHRINK: {
  1532.                 autoshrink = !autoshrink;
  1533.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1534.                 SetCtlValue(hitem, autoshrink ? 1 : 0);
  1535.                 break;
  1536.             }
  1537.             case WC_CLOSE: {
  1538.                 disposeonclose = !disposeonclose;
  1539.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1540.                 SetCtlValue(hitem, disposeonclose ? 1 : 0);
  1541.                 break;
  1542.             }
  1543.             case WC_BLOCK: {
  1544.                 blockcurs = !blockcurs;
  1545.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1546.                 SetCtlValue(hitem, blockcurs ? 1 : 0);
  1547.                 break;
  1548.             }
  1549.             case WC_BLINK: {
  1550.                 changecurs = !changecurs;
  1551.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1552.                 SetCtlValue(hitem, changecurs ? 1 : 0);
  1553.                 break;
  1554.             }
  1555.             case WC_EDITUPWRAP: {
  1556.                 editupwrap = !editupwrap;
  1557.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1558.                 SetCtlValue(hitem, editupwrap ? 1 : 0);
  1559.                 break;
  1560.             }
  1561.             case WC_EDITDOWNWRAP: {
  1562.                 editdownwrap = !editdownwrap;
  1563.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1564.                 SetCtlValue(hitem, editdownwrap ? 1 : 0);
  1565.                 break;
  1566.             }
  1567.             default: {
  1568.                 break;
  1569.             }
  1570.         }
  1571.     }
  1572. }
  1573.  
  1574.  
  1575. #define WC_EMTITLE    7        /* emulator name with 4 check boxes */
  1576.  
  1577.     /* skip line for bar */
  1578. #define WC_EM1        8
  1579. #define WC_EM2        9
  1580. #define WC_EM3        10
  1581. #define WC_EM4        11
  1582. #define WC_EM5        12
  1583. #define WC_EM6        13
  1584. #define WC_EM7        14
  1585.  
  1586. #define WC_VTROWS        17
  1587. #define WC_VTCOLS        18
  1588.  
  1589.  
  1590. /* configure emulator-specific session parameters; uses same basic fields
  1591.     as the setwindconf() dialog */
  1592.  
  1593. setvtconf()
  1594. {
  1595.     DialogPtr    wcdial;
  1596.     short    item_id;
  1597.     short    type;
  1598.     Rect rect;
  1599.     Handle hitem;
  1600.         /* general purpose GetDItem vars */
  1601.     GrafPtr    oport;
  1602.     short count;
  1603.     short termindex;
  1604.     char windtit[256];        /* temp for window title */
  1605.     
  1606.     /* ASCII things */
  1607.     short escmap;
  1608.     short ba_bs;
  1609.     short crtonl;
  1610.     short emwrap;
  1611.     short curseekmode;
  1612.     short ibm_keymode;
  1613.     short vtjumpscroll;
  1614.     
  1615.     short linecount;
  1616.     short linelength;
  1617.  
  1618.     if (chkbackground())
  1619.         return(-1);
  1620.  
  1621.     GetPort(&oport);
  1622.     if ((wcdial = GetNewDialog(DVTCONFIG, (Ptr) NULL, (WindowPtr) (-1))) == NULL)
  1623.         return(-1);
  1624.  
  1625.     getcontext(keydp);
  1626.     emwdeactivate();
  1627.     
  1628.     SetPort(wcdial);
  1629.     centerwind(wcdial);
  1630.  
  1631.     SetCursor(&arrow);
  1632.     showcursor();
  1633.     
  1634.     modaldialog = TRUE;
  1635.  
  1636.     GetDItem(wcdial, WC_OK, &type, &hitem, &okrect);
  1637.     buthilite(&okrect);
  1638.         /* hilite "OK" key */
  1639.  
  1640.     GetDItem(wcdial, WC_SESSIONNAME, &type, &hitem, &rect);
  1641.     GetWTitle(emdp->emwindow, &windtit[0]);
  1642.     SetIText(hitem, &windtit[0]);
  1643.         /* put the session name in the window */
  1644.  
  1645.     GetDItem(wcdial, WC_EMTITLE, &type, &hitem, &rect);
  1646.     SetIText(hitem, "\P ASCII emulator configuration");
  1647.     
  1648.     if (emdp->ibm_keymode) {
  1649.         /* hide all the ASCII-related controls */
  1650.         GetDItem(wcdial, WC_EM6, &type, &hitem, &rect);
  1651.         HideControl(hitem);
  1652.  
  1653.         GetDItem(wcdial, WC_EM7, &type, &hitem, &rect);
  1654.         HideControl(hitem);
  1655.     }
  1656.     GetDItem(wcdial, WC_EM1, &type, &hitem, &rect);
  1657.     SetCTitle(hitem, "\P Use IBM menus and key mapping");
  1658.     SetCtlValue(hitem, emdp->ibm_keymode ? 1 : 0);
  1659.  
  1660.     GetDItem(wcdial, WC_EM2, &type, &hitem, &rect);
  1661.     SetCTitle(hitem, "\P Map ` to Escape");
  1662.     SetCtlValue(hitem, emdp->escmap ? 1 : 0);
  1663.     
  1664.     GetDItem(wcdial, WC_EM3, &type, &hitem, &rect);
  1665.     SetCTitle(hitem, "\P Map Backspace to Delete");
  1666.     SetCtlValue(hitem, emdp->ba_bs ? 0 : 1);
  1667.     
  1668.     GetDItem(wcdial, WC_EM4, &type, &hitem, &rect);
  1669.     SetCTitle(hitem, "\P Map Return to Newline");
  1670.     SetCtlValue(hitem, emdp->crtonl ? 1 : 0);
  1671.     
  1672.     GetDItem(wcdial, WC_EM5, &type, &hitem, &rect);
  1673.     SetCTitle(hitem, "\P Wrap text when line overflows");
  1674.     SetCtlValue(hitem, emdp->wrap_around ? 1 : 0);
  1675.     
  1676.     GetDItem(wcdial, WC_EM6, &type, &hitem, &rect);
  1677.     SetCTitle(hitem, "\P Send vi commands to position cursor");
  1678.     SetCtlValue(hitem, emdp->curseekmode ? 1 : 0);
  1679.     
  1680.     GetDItem(wcdial, WC_EM7, &type, &hitem, &rect);
  1681.     SetCTitle(hitem, "\P Use VT100 jump scrolling mode");
  1682.     SetCtlValue(hitem, emdp->vtjumpscroll ? 1 : 0);
  1683.     
  1684.     GetDItem(wcdial, WC_VTROWS, &type, &hitem, &rect);
  1685.     sprintf(&windtit[0], "%d", emdp->linecount);
  1686.     ctop(&windtit[0]);
  1687.     SetIText(hitem, &windtit[0]);
  1688.     
  1689.     GetDItem(wcdial, WC_VTCOLS, &type, &hitem, &rect);
  1690.     sprintf(&windtit[0], "%d", emdp->linelength);
  1691.     ctop(&windtit[0]);
  1692.     SetIText(hitem, &windtit[0]);
  1693.  
  1694.     /* ASCII things */
  1695.     escmap = emdp->escmap;
  1696.     ba_bs = emdp->ba_bs;
  1697.     crtonl = emdp->crtonl;
  1698.     emwrap = emdp->wrap_around;
  1699.     curseekmode = emdp->curseekmode;
  1700.     ibm_keymode = emdp->ibm_keymode;
  1701.     vtjumpscroll = emdp->vtjumpscroll;
  1702.     
  1703.     linecount = emdp->linecount;
  1704.     linelength = emdp->linelength;
  1705.  
  1706.     while (TRUE) {
  1707.         ModalDialog((ProcPtr) alfilter, &item_id);
  1708.         termindex = item_id - 3;
  1709.         switch (item_id) {
  1710.             case WC_OK: {
  1711.                 if (ibm_keymode != emdp->ibm_keymode) {
  1712.                     SetPort(emdp->emwindow);
  1713.                     setibm_keymode(ibm_keymode);
  1714.                     SetPort(wcdial);
  1715.                 }
  1716.                     
  1717.                 /* update the settings */
  1718.                 /* ASCII things */
  1719.                 emdp->escmap = escmap;
  1720.                 emdp->ba_bs = ba_bs;
  1721.                 emdp->crtonl = crtonl;
  1722.                 emdp->wrap_around = emwrap;
  1723.                 emdp->ibm_keymode = ibm_keymode;
  1724.                 emdp->vtjumpscroll = vtjumpscroll;
  1725.                 emdp->curseekmode = curseekmode;
  1726.                 
  1727.                 wrap_around = emdp->wrap_around;        /* update global */
  1728.                 
  1729.                 GetDItem(wcdial, WC_VTROWS, &type, &hitem, &rect);
  1730.                 GetIText(hitem, &windtit[0]);
  1731.                 ptoc(&windtit[0]);
  1732.                 linecount = atoi(&windtit[0]);
  1733.                 
  1734.                 GetDItem(wcdial, WC_VTCOLS, &type, &hitem, &rect);
  1735.                 GetIText(hitem, &windtit[0]);
  1736.                 ptoc(&windtit[0]);
  1737.                 linelength = atoi(&windtit[0]);
  1738.                 
  1739.                 if (linelength != emdp->linelength
  1740.                     || linecount != emdp->linecount) {
  1741.                     /* size of emulator has changed */
  1742.                     if (linelength < 0 || linelength > 1000
  1743.                         || linecount < 0 || linecount > 32) {
  1744.             error("Sorry, only emulator sizes up to 32 X 1000 are valid");
  1745.                     }
  1746.                     else {
  1747.                         emdp->linecount = linecount;
  1748.                         emdp->linelength = linelength;
  1749.                         
  1750.                         useqd(emdp);        /* assume QD until next update since
  1751.                             new size may be incompatible with useds() */
  1752.                         termreset();
  1753.                         setscreensize(emdp->fontsize);
  1754.                     }
  1755.                 }
  1756.                 emdp->confchanged = TRUE;
  1757.                 
  1758.             }
  1759.             case WC_CANCEL: {
  1760.                 DisposDialog(wcdial);
  1761.                 SetPort(oport);
  1762.                 modaldialog = FALSE;
  1763.  
  1764.                 okrect.top = okrect.left = okrect.bottom = okrect.right = 0;
  1765.                 if (item_id == WC_CANCEL)
  1766.                     return(-1);
  1767.                 return(0);
  1768.             }
  1769.             case WC_HELP: {
  1770.                 helpwindow(TEXTEMDLOG, geneva, 9);
  1771.                 buthilite(&okrect);
  1772.                 break;
  1773.             }
  1774.             case WC_EM1: {
  1775.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1776.                 /* toggle IBM 7171/ASCII key mapping */
  1777.                 ibm_keymode = !ibm_keymode;
  1778.                 SetCtlValue(hitem, ibm_keymode ? 1 : 0);
  1779.                 /* setibm_keymode will be called later on... */
  1780.  
  1781.                 if (ibm_keymode) {
  1782.                     /* hide all the purely ASCII-related controls,
  1783.                         i.e., vi cursor mode */
  1784.                     GetDItem(wcdial, WC_EM6, &type, &hitem, &rect);
  1785.                     HideControl(hitem);
  1786.                     GetDItem(wcdial, WC_EM7, &type, &hitem, &rect);
  1787.                     HideControl(hitem);
  1788.                 }
  1789.                 else {
  1790.                     /* show all the ASCII-related controls */
  1791.                     GetDItem(wcdial, WC_EM6, &type, &hitem, &rect);
  1792.                     ShowControl(hitem);
  1793.                     GetDItem(wcdial, WC_EM7, &type, &hitem, &rect);
  1794.                     ShowControl(hitem);
  1795.                 }
  1796.                 break;
  1797.             }
  1798.             case WC_EM2: {
  1799.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1800.                 escmap = !escmap;
  1801.                 SetCtlValue(hitem, escmap ? 1 : 0);
  1802.                 break;
  1803.             }
  1804.             case WC_EM3: {
  1805.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1806.                 ba_bs = !ba_bs;
  1807.                 SetCtlValue(hitem, ba_bs ? 0 : 1);
  1808.                 break;
  1809.             }
  1810.             case WC_EM4: {
  1811.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1812.                 crtonl = !crtonl;
  1813.                 SetCtlValue(hitem, crtonl ? 1 : 0);
  1814.                 break;
  1815.             }
  1816.             case WC_EM5: {
  1817.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1818.                 emwrap = !emwrap;
  1819.                 SetCtlValue(hitem, emwrap ? 1 : 0);
  1820.                 break;
  1821.             }
  1822.             case WC_EM6: {
  1823.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1824.                 curseekmode = !curseekmode;
  1825.                 SetCtlValue(hitem, curseekmode ? 1 : 0);
  1826.                 break;
  1827.             }
  1828.             case WC_EM7: {
  1829.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1830.                 /* toggle vt100 jump scroll mode */
  1831.                 vtjumpscroll = !vtjumpscroll;
  1832.                 SetCtlValue(hitem, vtjumpscroll ? 1 : 0);
  1833.                 break;
  1834.             }
  1835.             default: {
  1836.                 break;
  1837.             }
  1838.         }
  1839.     }
  1840. }
  1841.  
  1842.     /* skip line for bar */
  1843. #define WC_EM1        8
  1844. #define WC_EM2        9
  1845. #define WC_EM3        10
  1846. #define WC_EM4        11
  1847. #define WC_IBMMOD2        12
  1848. #define WC_IBMMOD3        13
  1849. #define WC_IBMMOD5        14
  1850.  
  1851.  
  1852. /* configure emulator-specific session parameters; uses same basic fields
  1853.     as the setwindconf() dialog */
  1854.  
  1855. set3270conf()
  1856. {
  1857.     DialogPtr    wcdial;
  1858.     short    item_id;
  1859.     short    type;
  1860.     Rect rect;
  1861.     Handle hitem;
  1862.         /* general purpose GetDItem vars */
  1863.     GrafPtr    oport;
  1864.     short count;
  1865.     short termindex;
  1866.     char windtit[256];        /* temp for window title */
  1867.     
  1868.     /* IBM things */
  1869.     short typeahead;
  1870.     short nullsareblanks;
  1871.     short squeezeblanks;
  1872.     short shiftfield;
  1873.     short ibm_type;
  1874.     
  1875.     if (chkbackground())
  1876.         return(-1);
  1877.  
  1878.     GetPort(&oport);
  1879.     if ((wcdial = GetNewDialog(D3270CONFIG, (Ptr) NULL, (WindowPtr) (-1))) == NULL)
  1880.         return(-1);
  1881.  
  1882.     getcontext(keydp);
  1883.     emwdeactivate();
  1884.     
  1885.     SetPort(wcdial);
  1886.     centerwind(wcdial);
  1887.  
  1888.     SetCursor(&arrow);
  1889.     showcursor();
  1890.     
  1891.     modaldialog = TRUE;
  1892.  
  1893.     GetDItem(wcdial, WC_OK, &type, &hitem, &okrect);
  1894.     buthilite(&okrect);
  1895.         /* hilite "OK" key */
  1896.  
  1897.     GetDItem(wcdial, WC_SESSIONNAME, &type, &hitem, &rect);
  1898.     GetWTitle(emdp->emwindow, &windtit[0]);
  1899.     SetIText(hitem, &windtit[0]);
  1900.         /* put the session name in the window */
  1901.  
  1902.     GetDItem(wcdial, WC_EMTITLE, &type, &hitem, &rect);
  1903.  
  1904.     SetIText(hitem, "\P IBM 3278 emulator configuration");
  1905.  
  1906.     GetDItem(wcdial, WC_EM1, &type, &hitem, &rect);
  1907.     SetCTitle(hitem, "\P Typeahead: allow input when System Busy");
  1908.     SetCtlValue(hitem, emdp->typeahead ? 1 : 0);
  1909.     
  1910.     GetDItem(wcdial, WC_EM2, &type, &hitem, &rect);
  1911.     SetCTitle(hitem, "\P Send Imbedded 3278 Nulls as Blanks");
  1912.     SetCtlValue(hitem, emdp->nullsareblanks ? 1 : 0);
  1913.     
  1914.     GetDItem(wcdial, WC_EM3, &type, &hitem, &rect);
  1915.     SetCtlValue(hitem, emdp->squeezeblanks ? 1 : 0);
  1916.     SetCTitle(hitem, "\P Squeeze out blanks at end of field in Insert mode");
  1917.     
  1918.     GetDItem(wcdial, WC_EM4, &type, &hitem, &rect);
  1919.     SetCTitle(hitem, "\P Shift whole field when deleting characters");
  1920.     SetCtlValue(hitem, emdp->shiftfield ? 1 : 0);
  1921.     
  1922.     ibmtypebutset(wcdial, emdp->ibm_type + WC_IBMMOD2);
  1923.  
  1924.     /* IBM things */
  1925.     typeahead = emdp->typeahead;
  1926.     nullsareblanks = emdp->nullsareblanks;
  1927.     squeezeblanks = emdp->squeezeblanks;
  1928.     shiftfield = emdp->shiftfield;
  1929.     ibm_type = emdp->ibm_type;
  1930.     
  1931.     while (TRUE) {
  1932.         ModalDialog((ProcPtr) alfilter, &item_id);
  1933.         termindex = item_id - 3;
  1934.         switch (item_id) {
  1935.             case WC_OK: {
  1936.                     
  1937.                 /* update the settings */
  1938.                 /* IBM things */
  1939.                 emdp->typeahead = typeahead;
  1940.                 emdp->nullsareblanks = nullsareblanks;
  1941.                 emdp->squeezeblanks = squeezeblanks;
  1942.                 emdp->shiftfield = shiftfield;
  1943.                 
  1944.                 if (emdp->ibm_type != ibm_type)
  1945.                     error("IBM terminal type changes will take effect the next time you open the session document");
  1946.                 emdp->ibm_type = ibm_type;
  1947.                 
  1948.                 emdp->confchanged = TRUE;
  1949.                 
  1950.             }
  1951.             case WC_CANCEL: {
  1952.                 DisposDialog(wcdial);
  1953.                 SetPort(oport);
  1954.                 modaldialog = FALSE;
  1955.  
  1956.                 okrect.top = okrect.left = okrect.bottom = okrect.right = 0;
  1957.                 if (item_id == WC_CANCEL)
  1958.                     return(-1);
  1959.                 return(0);
  1960.             }
  1961.             case WC_HELP: {
  1962.                 helpwindow(TEXT3270DLOG, geneva, 9);
  1963.                 buthilite(&okrect);
  1964.                 break;
  1965.             }
  1966.             case WC_EM1: {
  1967.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1968.                 typeahead = !typeahead;
  1969.                 SetCtlValue(hitem, typeahead ? 1 : 0);
  1970.                 break;
  1971.             }
  1972.             case WC_EM2: {
  1973.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1974.                 nullsareblanks = !nullsareblanks;
  1975.                 SetCtlValue(hitem, nullsareblanks ? 1 : 0);
  1976.                 break;
  1977.             }
  1978.             case WC_EM3: {
  1979.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1980.                 squeezeblanks = !squeezeblanks;
  1981.                 SetCtlValue(hitem, squeezeblanks ? 1 : 0);
  1982.                 break;
  1983.             }
  1984.             case WC_EM4: {
  1985.                 GetDItem(wcdial, item_id, &type, &hitem, &rect);
  1986.                 shiftfield = !shiftfield;
  1987.                 SetCtlValue(hitem, shiftfield ? 1 : 0);
  1988.                 break;
  1989.             }
  1990.             case WC_IBMMOD2: 
  1991.             case WC_IBMMOD3: 
  1992.             case WC_IBMMOD5: 
  1993.             {
  1994.                 ibm_type = item_id - WC_IBMMOD2;
  1995.                 ibmtypebutset(wcdial, item_id);
  1996.                 break;
  1997.             }
  1998.             default: {
  1999.                 break;
  2000.             }
  2001.         }
  2002.     }
  2003. }
  2004.  
  2005. /* set the button selected and reset the others */
  2006.  
  2007. ibmtypebutset(dlog, itemid)
  2008. DialogPtr dlog;
  2009. short itemid;
  2010. {
  2011.     short    type;
  2012.     Rect rect;
  2013.     Handle hitem;
  2014.  
  2015.     GetDItem(dlog, WC_IBMMOD2, &type, &hitem, &rect);
  2016.     SetCtlValue(hitem, itemid == WC_IBMMOD2 ? 1 : 0);
  2017.     GetDItem(dlog, WC_IBMMOD3, &type, &hitem, &rect);
  2018.     SetCtlValue(hitem, itemid == WC_IBMMOD3 ? 1 : 0);
  2019.     GetDItem(dlog, WC_IBMMOD5, &type, &hitem, &rect);
  2020.     SetCtlValue(hitem, itemid == WC_IBMMOD5 ? 1 : 0);
  2021. }
  2022.  
  2023.  
  2024. /* perform a dialog to do Global Configuration */
  2025.  
  2026. #define GC_OK            1
  2027. #define GC_CANCEL        2
  2028. #define GC_TITLE        3        /* 12 types are allocated in the dialog */
  2029. #define GC_HELP            4        /* type #s must correspond to this list */
  2030. #define GC_SAVE            5
  2031.  
  2032. #define GC_TRYDSDRAW    6
  2033. #define GC_RISKYDSDRAW    7
  2034. #define GC_MTCPSENDASYNC    8
  2035. #define GC_EDRESETSELECT    9
  2036. #define GC_QUITONCLOSE    10
  2037. #define GC_TFTPSERVE    11
  2038. #define GC_TFTPASK        12
  2039. #define GC_COURIER        13
  2040.  
  2041.  
  2042. setglobalconf()
  2043. {
  2044.     DialogPtr    gcdial;
  2045.     short    item_id;
  2046.     short    type;
  2047.     Rect rect;
  2048.     Handle hitem;
  2049.         /* general purpose GetDItem vars */
  2050.     GrafPtr    oport;
  2051.     short count;
  2052.     short termindex;
  2053.     
  2054.     /* vars we work on */
  2055.     short otrydsdraw;
  2056.     short oquitonclose;
  2057.     short otftpserve;
  2058.     short otftpask;
  2059.     short ocourierprint;
  2060.     short oriskydsdraw;
  2061.     short omtcpsendasync;
  2062.     short oedresetselect;
  2063.     
  2064.     if (chkbackground())
  2065.         return(-1);
  2066.  
  2067.     GetPort(&oport);
  2068.     if ((gcdial = GetNewDialog(DGLOBALCONFIG, (Ptr) NULL, (WindowPtr) (-1))) == NULL)
  2069.         return(-1);
  2070.  
  2071.     getcontext(keydp);
  2072.     emwdeactivate();
  2073.     
  2074.     centerwind(gcdial);
  2075.  
  2076.     SetCursor(&arrow);
  2077.     showcursor();
  2078.     
  2079.     SetPort(gcdial);
  2080.     modaldialog = TRUE;
  2081.  
  2082.     GetDItem(gcdial, GC_OK, &type, &hitem, &okrect);
  2083.     buthilite(&okrect);
  2084.         /* hilite "OK" key */
  2085.  
  2086.     GetDItem(gcdial, GC_TRYDSDRAW, &type, &hitem, &rect);
  2087.     SetCtlValue(hitem, trydsdraw ? 1 : 0);
  2088.     
  2089.     GetDItem(gcdial, GC_RISKYDSDRAW, &type, &hitem, &rect);
  2090.     SetCtlValue(hitem, riskydsdraw ? 0 : 1);    /* sense is "restrict drawing" */
  2091.     
  2092.     GetDItem(gcdial, GC_MTCPSENDASYNC, &type, &hitem, &rect);
  2093.     SetCtlValue(hitem, mtcpsendasync ? 1 : 0);
  2094.     
  2095.     GetDItem(gcdial, GC_EDRESETSELECT, &type, &hitem, &rect);
  2096.     SetCtlValue(hitem, edresetselect ? 1 : 0);
  2097.     
  2098.     GetDItem(gcdial, GC_QUITONCLOSE, &type, &hitem, &rect);
  2099.     SetCtlValue(hitem, quitonclose ? 1 : 0);
  2100.     
  2101.     GetDItem(gcdial, GC_TFTPSERVE, &type, &hitem, &rect);
  2102.     SetCtlValue(hitem, tftpserve == TFYES ? 1 : 0);
  2103.     
  2104.     GetDItem(gcdial, GC_TFTPASK, &type, &hitem, &rect);
  2105.     SetCtlValue(hitem, tftpask == TFYES ? 1 : 0);
  2106.     
  2107.     GetDItem(gcdial, GC_COURIER, &type, &hitem, &rect);
  2108.     SetCtlValue(hitem, courierprint ? 1 : 0);
  2109.     
  2110.     /* get current settings: note that 'o' prefix means *new*, whups! */
  2111.     otrydsdraw = trydsdraw;
  2112.     oquitonclose = quitonclose;
  2113.     oriskydsdraw = riskydsdraw;
  2114.     omtcpsendasync = mtcpsendasync;
  2115.     oedresetselect = edresetselect;
  2116.     otftpserve = tftpserve;
  2117.     otftpask = tftpask;
  2118.     ocourierprint = courierprint;
  2119.     
  2120.     while (TRUE) {
  2121.         ModalDialog((ProcPtr) alfilter, &item_id);
  2122.         switch (item_id) {
  2123.             case GC_CANCEL: {
  2124.                 /* restore the old settings */
  2125.                 DisposDialog(gcdial);
  2126.                 SetPort(oport);
  2127.                 modaldialog = FALSE;
  2128.  
  2129.                 okrect.top = okrect.left = okrect.bottom = okrect.right = 0;
  2130.                 return(-1);
  2131.             }
  2132.             case GC_OK: {
  2133.                 trydsdraw = otrydsdraw;
  2134.                 quitonclose = oquitonclose;
  2135.                 tftpserve = otftpserve;
  2136.                 tftpask = otftpask;
  2137.                 riskydsdraw = oriskydsdraw;
  2138.                 mtcpsendasync = omtcpsendasync;
  2139.                 edresetselect = oedresetselect;
  2140.                 courierprint = ocourierprint;
  2141.  
  2142.                 DisposDialog(gcdial);
  2143.                 SetPort(oport);
  2144.                 modaldialog = FALSE;
  2145.                 if (tftpserve == TFYES)
  2146.                     tfs_on();
  2147.                 else
  2148.                     tfs_off();
  2149.  
  2150.                 if (keydp != NULL) 
  2151.                     InvalRect(&keydp->bigrect);
  2152.                     
  2153.                 if (trydsdraw != otrydsdraw) {
  2154.                     testdsall();
  2155.                 }
  2156.  
  2157.                 okrect.top = okrect.left = okrect.bottom = okrect.right = 0;
  2158.                 return(0);
  2159.             }
  2160.             case GC_SAVE: {
  2161.                 /* update the globals for saveglobalconfig() */
  2162.                 trydsdraw = otrydsdraw;
  2163.                 quitonclose = oquitonclose;
  2164.                 tftpserve = otftpserve;
  2165.                 tftpask = otftpask;
  2166.                 riskydsdraw = oriskydsdraw;
  2167.                 mtcpsendasync = omtcpsendasync;
  2168.                 edresetselect = oedresetselect;
  2169.                 courierprint = ocourierprint;
  2170.                 
  2171.                 if (saveglobalconfig())
  2172.                     error("Save failed");            /* save it in the Comet settings file */
  2173.  
  2174.                 break;
  2175.             }
  2176.             case GC_HELP: {
  2177.                 helpwindow(TEXTGLOBALDLOG, geneva, 9);
  2178.                 buthilite(&okrect);
  2179.                 break;
  2180.             }
  2181.             case GC_TRYDSDRAW: {
  2182.                 otrydsdraw = !otrydsdraw;
  2183.                 GetDItem(gcdial, item_id, &type, &hitem, &rect);
  2184.                 SetCtlValue(hitem, otrydsdraw ? 1 : 0);
  2185.                 break;
  2186.             }
  2187.             case GC_QUITONCLOSE: {
  2188.                 oquitonclose = !oquitonclose;
  2189.                 GetDItem(gcdial, item_id, &type, &hitem, &rect);
  2190.                 SetCtlValue(hitem, oquitonclose ? 1 : 0);
  2191.                 break;
  2192.             }
  2193.             case GC_COURIER: {
  2194.                 ocourierprint = !ocourierprint;
  2195.                 GetDItem(gcdial, item_id, &type, &hitem, &rect);
  2196.                 SetCtlValue(hitem, ocourierprint ? 1 : 0);
  2197.                 break;
  2198.             }
  2199.             case GC_TFTPSERVE: {
  2200.                 if (otftpserve == TFYES)
  2201.                     otftpserve = TFNO;
  2202.                 else
  2203.                     otftpserve = TFYES;
  2204.                 GetDItem(gcdial, item_id, &type, &hitem, &rect);
  2205.                 SetCtlValue(hitem, otftpserve == TFYES ? 1 : 0);
  2206.                 break;
  2207.             }
  2208.             case GC_TFTPASK: {
  2209.                 if (otftpask == TFYES)
  2210.                     otftpask = TFNO;
  2211.                 else
  2212.                     otftpask = TFYES;
  2213.                 GetDItem(gcdial, item_id, &type, &hitem, &rect);
  2214.                 SetCtlValue(hitem, otftpask == TFYES ? 1 : 0);
  2215.                 break;
  2216.             }
  2217.             case GC_RISKYDSDRAW: {
  2218.                 oriskydsdraw = !oriskydsdraw;
  2219.                 GetDItem(gcdial, item_id, &type, &hitem, &rect);
  2220.                 SetCtlValue(hitem, oriskydsdraw ? 0 : 1);
  2221.                 break;
  2222.             }
  2223.             case GC_MTCPSENDASYNC: {
  2224.                 omtcpsendasync = !omtcpsendasync;
  2225.                 GetDItem(gcdial, item_id, &type, &hitem, &rect);
  2226.                 SetCtlValue(hitem, omtcpsendasync ? 1 : 0);
  2227.                 break;
  2228.             }
  2229.             case GC_EDRESETSELECT: {
  2230.                 oedresetselect = !oedresetselect;
  2231.                 GetDItem(gcdial, item_id, &type, &hitem, &rect);
  2232.                 SetCtlValue(hitem, oedresetselect ? 1 : 0);
  2233.                 break;
  2234.             }
  2235.             default: {
  2236.                 break;
  2237.             }
  2238.         }
  2239.     }
  2240. }
  2241.  
  2242.  
  2243.  
  2244. queryclosewind(twp)
  2245. struct winds * twp;
  2246. {
  2247.     if (twp == emdp)
  2248.         savecontext(emdp);
  2249.     else
  2250.         getcontext(twp);
  2251.  
  2252.     if (twp->connopen) {
  2253.         error("Sorry, you must close the window's session first");
  2254.         return(-1);
  2255.     }
  2256.     if (queryconfchange(twp))
  2257.         return(-1);
  2258.     
  2259.     /* save the window position */
  2260.     reopenconfig(twp);
  2261.     saveonewindpos(twp);
  2262.     closeconfig(twp);
  2263.     
  2264.     /* TODO must release all terminal memory */
  2265.     killwind(twp);
  2266.     releaseconfig();
  2267.     releaseconn(twp);
  2268.     
  2269.     return(0);
  2270. }
  2271.  
  2272.  
  2273. /* ask the user whether the configuration should be saved */
  2274.  
  2275. queryconfchange(twp)
  2276. struct winds * twp;
  2277. {
  2278.     short item;
  2279.     DialogPtr dptr;
  2280.     GrafPtr oport;
  2281.     short type;
  2282.     Rect rect;
  2283.     Handle hitem;
  2284.         /* general purpose GetDItem vars */
  2285.         
  2286.     if (twp->confchanged) {
  2287.         /* give user the option of saving the configuration */
  2288.         if (!twp->backonly) {
  2289.             GetPort(&oport);
  2290.             chkbackground();
  2291.             HLock(twp->hhostname);
  2292.             ParamText(*twp->hhostname, "\P", "\P", "\P");
  2293.             HUnlock(twp->hhostname);
  2294.             if ( (dptr = GetNewDialog(SAVEDIALOG, (Ptr) NULL, (WindowPtr) -1))
  2295.                     != NULL)  {
  2296.  
  2297.                 emwdeactivate();
  2298.                 SetPort(dptr);
  2299.                 centerwind(dptr);
  2300.                 
  2301.                 /* hilite "Save" key */
  2302.                 GetDItem(dptr, SD_SAVE, &type, &hitem, &rect);
  2303.                 buthilite(&rect);
  2304.  
  2305.                 modaldialog = TRUE;
  2306.                 do {
  2307.                     ModalDialog( (ProcPtr) alfilter, &item);
  2308.                 }
  2309.                 while (item == 0);
  2310.  
  2311.                 DisposDialog(dptr);
  2312.                 SetPort(oport);
  2313.                 modaldialog = FALSE;
  2314.                 if (item == SD_CANCEL) {
  2315.                     /* cancel whatever procedure called us */
  2316.                     return(-1);
  2317.                 }
  2318.                 else if (item == SD_SAVE) {
  2319.                     getcontext(twp);
  2320.                     if (optkeydown()) {
  2321.                         namewindow();
  2322.                     }
  2323.                     saveconfig(emdp, creator);
  2324.                 }
  2325.                 else if (item == SD_DONT) {
  2326.                     twp->confchanged = FALSE;
  2327.                 }
  2328.             }
  2329.         }
  2330.     }
  2331.     /* we arrive here if we didn't care to save, too */
  2332.     return(0);
  2333. }
  2334.  
  2335.  
  2336. querycloseconn(twp)
  2337. struct winds * twp;
  2338. {
  2339.     short item;
  2340.     DialogPtr dptr;
  2341.     GrafPtr oport;
  2342.     short type;
  2343.     Rect rect;
  2344.     Handle hitem;
  2345.     
  2346.     if (!mfbackonly && twp->connopen) {
  2347.         /* some connection has been attempted, get user's OK */
  2348.         GetPort(&oport);
  2349.         chkbackground();
  2350.         HLock(twp->hhostname);
  2351.         ParamText(*twp->hhostname, "\P", "\P", "\P");
  2352.         HUnlock(twp->hhostname);
  2353.         if ( (dptr = GetNewDialog(QUITDIALOG, (Ptr) NULL, (WindowPtr) -1))
  2354.                 != NULL)  {
  2355.  
  2356.             emwdeactivate();
  2357.             SetPort(dptr);
  2358.             centerwind(dptr);
  2359.             
  2360.             /* hilite "OK" key */
  2361.             GetDItem(dptr, QUITOK, &type, &hitem, &rect);
  2362.             buthilite(&rect);
  2363.  
  2364.             modaldialog = TRUE;
  2365.             do {
  2366.                 ModalDialog( (ProcPtr) alfilter, &item);
  2367.             }
  2368.             while (item == 0);
  2369.  
  2370.             DisposDialog(dptr);
  2371.             SetPort(oport);
  2372.             modaldialog = FALSE;
  2373.             if (item == QUITCANCEL) {
  2374.                 return(TRUE);
  2375.             }
  2376.         }
  2377.         /* go ahead and close up the connections... */
  2378.     }
  2379.     return(FALSE);
  2380. }
  2381.  
  2382.  
  2383. /* if the configuration file has not been saved, prompt the user to do so */
  2384.  
  2385. querynewconf()
  2386. {
  2387.     if (keydp->newconf) {
  2388.         error("You need to save this new document before defining macros");
  2389.         getcontext(keydp);
  2390.         if (optkeydown()) {
  2391.             namewindow();
  2392.         }
  2393.         saveconfig(keydp, creator);
  2394.         if (keydp->newconf)
  2395.             /* it's still not open */
  2396.             return(TRUE);
  2397.     }
  2398.     return(FALSE);
  2399. }
  2400.  
  2401.  
  2402.  
  2403. /* perform a dialog to set the key pad */
  2404.  
  2405. #define KD_OK    1
  2406. #define KD_CANCEL    2
  2407. #define KD_PICBOX    3
  2408. #define KD_NORMKEY    4
  2409. #define KD_KEYPAD1    5
  2410. #define KD_KEYPAD2    6
  2411. #define KD_KEYPAD3    7
  2412. #define KD_KEYPAD4    8
  2413.  
  2414. #define KD_SWITCHKEY    9
  2415. #define KD_SESSIONNAME    10
  2416.  
  2417. setibmkeypad()
  2418. {
  2419.     DialogPtr    kpdial;
  2420.     int    item_id;
  2421.     int    type;
  2422.     Rect rect;
  2423.     Rect picrect;
  2424.     Handle hitem;
  2425.         /* general purpose GetDItem vars */
  2426.     GrafPtr    oport;
  2427.     short okeypad;
  2428.     short okeypadswitch;
  2429.     int count;
  2430.     PicHandle keypic[4];
  2431.     char windtit[256];        /* temp for window title */
  2432.  
  2433.     GetPort(&oport);
  2434.  
  2435.     if (chkbackground())
  2436.         return(0);
  2437.         
  2438.     if ((kpdial = GetNewDialog(DSETKEYPAD, (Ptr) NULL, (WindowPtr) (-1))) == NULL)
  2439.         return(0);
  2440.  
  2441.     getcontext(keydp);
  2442.     emwdeactivate();
  2443.     
  2444.     centerwind(kpdial);
  2445.  
  2446.     SetCursor(&arrow);
  2447.     showcursor();
  2448.     SetPort(kpdial);
  2449.     
  2450.     modaldialog = TRUE;
  2451.  
  2452.     okeypad = keydp->keypad;
  2453.     okeypadswitch = keypadswitch;
  2454.  
  2455.     GetDItem(kpdial, KD_OK, &type, &hitem, &rect);
  2456.     buthilite(&rect);
  2457.         /* hilite "OK" key */
  2458.  
  2459.     GetDItem(kpdial, KD_SESSIONNAME, &type, &hitem, &rect);
  2460.     GetWTitle(emdp->emwindow, &windtit[0]);
  2461.     SetIText(hitem, &windtit[0]);
  2462.         /* put the session name in the window */
  2463.  
  2464.     for (count = 0; count < NUMKEYPICS; count++)
  2465.         keypic[count] = (PicHandle) GetResource('PICT', PICKEYP1 + count);
  2466.  
  2467.     /* highlight current selection and display */
  2468.     GetDItem(kpdial, KD_PICBOX, &type, &hitem, &picrect);
  2469.     kpdialbutset(kpdial, keydp->keypad + KD_NORMKEY);
  2470.     DrawPicture(keypic[keydp->keypad], &picrect);
  2471.     
  2472.     /* set keypadswitch check box */
  2473.     GetDItem(kpdial, KD_SWITCHKEY, &type, &hitem, &rect);
  2474.     SetCtlValue(hitem, keypadswitch ? 1 : 0);
  2475.  
  2476.     while (TRUE) {
  2477.         ModalDialog((ProcPtr) alfilter, &item_id);
  2478.         switch (item_id) {
  2479.             case KD_CANCEL:
  2480.                 keydp->keypad = okeypad;
  2481.                 keypadswitch = okeypadswitch;
  2482.             case KD_OK: {
  2483.                 pfmenuhack(keydp);
  2484.                 
  2485.                 if (keypadswitch != okeypadswitch && saveglobalconfig())
  2486.                     error(keyswerr);            /* save it in the Comet settings file */
  2487.  
  2488.                 DisposDialog(kpdial);
  2489.                 SetPort(oport);
  2490.                 modaldialog = FALSE;
  2491.  
  2492.                 okrect.top = okrect.left = okrect.bottom = okrect.right = 0;
  2493.                 if (item_id == KD_CANCEL)
  2494.                     return(0);
  2495.                 else
  2496.                     return(TRUE);
  2497.             }
  2498.             case KD_NORMKEY: {
  2499.                 keydp->keypad = NORMKEYPAD;
  2500.                 kpdialbutset(kpdial, item_id);
  2501.                 DrawPicture(keypic[keydp->keypad], &picrect);
  2502.                 break;
  2503.             }
  2504.             case KD_KEYPAD1: {
  2505.                 keydp->keypad = KEYPAD1;
  2506.                 kpdialbutset(kpdial, item_id);
  2507.                 DrawPicture(keypic[keydp->keypad], &picrect);
  2508.                 break;
  2509.             }
  2510.             case KD_KEYPAD2: {
  2511.                 keydp->keypad = KEYPAD2;
  2512.                 kpdialbutset(kpdial, item_id);
  2513.                 DrawPicture(keypic[keydp->keypad], &picrect);
  2514.                 break;
  2515.             }
  2516.             case KD_KEYPAD3: {
  2517.                 keydp->keypad = KEYPAD3;
  2518.                 kpdialbutset(kpdial, item_id);
  2519.                 DrawPicture(keypic[keydp->keypad], &picrect);
  2520.                 break;
  2521.             }
  2522.             case KD_SWITCHKEY: {
  2523.                 keypadswitch = !keypadswitch;
  2524.                 GetDItem(kpdial, item_id, &type, &hitem, &rect);
  2525.                 SetCtlValue(hitem, keypadswitch ? 1 : 0);
  2526.                 break;
  2527.             }
  2528.             default: {
  2529.                 break;
  2530.             }
  2531.         }
  2532.     }
  2533. }
  2534.  
  2535.  
  2536. /* set the button selected and reset the others */
  2537.  
  2538. kpdialbutset(dlog, itemid)
  2539. DialogPtr dlog;
  2540. short itemid;
  2541. {
  2542.     short    type;
  2543.     Rect rect;
  2544.     Handle hitem;
  2545.  
  2546.     GetDItem(dlog, KD_NORMKEY, &type, &hitem, &rect);
  2547.     SetCtlValue(hitem, itemid == KD_NORMKEY ? 1 : 0);
  2548.     GetDItem(dlog, KD_KEYPAD1, &type, &hitem, &rect);
  2549.     SetCtlValue(hitem, itemid == KD_KEYPAD1 ? 1 : 0);
  2550.     GetDItem(dlog, KD_KEYPAD2, &type, &hitem, &rect);
  2551.     SetCtlValue(hitem, itemid == KD_KEYPAD2 ? 1 : 0);
  2552.     GetDItem(dlog, KD_KEYPAD3, &type, &hitem, &rect);
  2553.     SetCtlValue(hitem, itemid == KD_KEYPAD3 ? 1 : 0);
  2554. }
  2555.  
  2556.  
  2557. /* perform a dialog to set the VT100 key pad */
  2558.  
  2559. setvtkeypad()
  2560. {
  2561.     DialogPtr    kpdial;
  2562.     int    item_id;
  2563.     int    type;
  2564.     Rect rect;
  2565.     Rect picrect;
  2566.     Handle hitem;
  2567.         /* general purpose GetDItem vars */
  2568.     GrafPtr    oport;
  2569.     short nvtkeypad;
  2570.     short nvtaltcursor;
  2571.     short nvtaltkeypad;
  2572.     short okeypadswitch;
  2573.     
  2574.     int count;
  2575.     PicHandle keypic[4];
  2576.     char windtit[256];        /* temp for window title */
  2577.  
  2578.     GetPort(&oport);
  2579.  
  2580.     if (chkbackground())
  2581.         return(0);
  2582.         
  2583.     if ((kpdial = GetNewDialog(DVTSETKEYPAD, (Ptr) NULL, (WindowPtr) (-1))) == NULL)
  2584.         return(0);
  2585.  
  2586.     getcontext(keydp);
  2587.     emwdeactivate();
  2588.     
  2589.     centerwind(kpdial);
  2590.  
  2591.     SetCursor(&arrow);
  2592.     showcursor();
  2593.     SetPort(kpdial);
  2594.     
  2595.     modaldialog = TRUE;
  2596.  
  2597.     nvtkeypad = keydp->vtkeypad;
  2598.     nvtaltkeypad = keydp->vtaltkeypad;
  2599.     nvtaltcursor = keydp->vtaltcursor;
  2600.     okeypadswitch = keypadswitch;
  2601.     
  2602.     GetDItem(kpdial, KD_OK, &type, &hitem, &rect);
  2603.     buthilite(&rect);
  2604.         /* hilite "OK" key */
  2605.  
  2606.     GetDItem(kpdial, KD_SESSIONNAME, &type, &hitem, &rect);
  2607.     GetWTitle(emdp->emwindow, &windtit[0]);
  2608.     SetIText(hitem, &windtit[0]);
  2609.         /* put the session name in the window */
  2610.  
  2611.     for (count = 0; count < NUMVTKEYPICS; count++)
  2612.         keypic[count] = (PicHandle) GetResource('PICT', VTPICKEYP1 + count);
  2613.  
  2614.     /* highlight current selection and display */
  2615.     GetDItem(kpdial, KD_PICBOX, &type, &hitem, &picrect);
  2616.     vtkpbutset(kpdial, keydp->vtkeypad + KD_NORMKEY);
  2617.     
  2618.     if (keydp->vtkeypad) {
  2619.         DrawPicture(keypic[keydp->vtkeypad - 1], &picrect);
  2620.     }
  2621.     else {
  2622.         /* automatic mode, set pic according to current settings */
  2623.         if (!keydp->vtaltkeypad) {
  2624.             DrawPicture(keypic[KD_KEYPAD1 - 5], &picrect);
  2625.         }
  2626.         else {
  2627.             if (keydp->vtaltcursor == 'O')
  2628.                 DrawPicture(keypic[KD_KEYPAD2 - 5], &picrect);
  2629.             else
  2630.                 DrawPicture(keypic[KD_KEYPAD3 - 5], &picrect);
  2631.         }
  2632.     }
  2633.     
  2634.     /* set keypadswitch check box */
  2635.     GetDItem(kpdial, KD_SWITCHKEY, &type, &hitem, &rect);
  2636.     SetCtlValue(hitem, keypadswitch ? 1 : 0);
  2637.  
  2638.     while (TRUE) {
  2639.         ModalDialog((ProcPtr) alfilter, &item_id);
  2640.         switch (item_id) {
  2641.             case KD_OK: {
  2642.                 keydp->vtkeypad = nvtkeypad;
  2643.                 keydp->vtaltkeypad = nvtaltkeypad;
  2644.                 keydp->vtaltcursor = nvtaltcursor;
  2645.                 keypadswitch = okeypadswitch;
  2646.                 /* fall through */
  2647.             case KD_CANCEL:
  2648.                 if (keypadswitch != okeypadswitch && saveglobalconfig())
  2649.                     error(keyswerr);            /* save it in the Comet settings file */
  2650.  
  2651.                 DisposDialog(kpdial);
  2652.                 SetPort(oport);
  2653.                 modaldialog = FALSE;
  2654.  
  2655.                 okrect.top = okrect.left = okrect.bottom = okrect.right = 0;
  2656.                 if (item_id == KD_CANCEL)
  2657.                     return(0);
  2658.                 else
  2659.                     return(TRUE);
  2660.             }
  2661.             case KD_NORMKEY: {
  2662.                 nvtkeypad = 0;
  2663.                 vtkpbutset(kpdial, item_id);
  2664.                 /* automatic mode, set pic according to current settings */
  2665.                 if (!keydp->vtaltkeypad) {
  2666.                     DrawPicture(keypic[KD_KEYPAD1 - 5], &picrect);
  2667.                 }
  2668.                 else {
  2669.                     if (keydp->vtaltcursor == 'O')
  2670.                         DrawPicture(keypic[KD_KEYPAD2 - 5], &picrect);
  2671.                     else
  2672.                         DrawPicture(keypic[KD_KEYPAD3 - 5], &picrect);
  2673.                 }
  2674.                 break;
  2675.             }
  2676.             case KD_KEYPAD1: {
  2677.                 /* calculator keypad */
  2678.                 nvtkeypad = KEYPAD1;
  2679.                 nvtaltkeypad = FALSE;
  2680.                 vtkpbutset(kpdial, item_id);
  2681.                 DrawPicture(keypic[nvtkeypad - 1], &picrect);
  2682.                 break;
  2683.             }
  2684.             case KD_KEYPAD2: {
  2685.                 /* application */
  2686.                 nvtkeypad = KEYPAD2;
  2687.                 nvtaltkeypad = TRUE;
  2688.                 nvtaltcursor = 'O';
  2689.                 vtkpbutset(kpdial, item_id);
  2690.                 DrawPicture(keypic[nvtkeypad - 1], &picrect);
  2691.                 break;
  2692.             }
  2693.             case KD_KEYPAD3: {
  2694.                 /* application alternate cursor mode */
  2695.                 nvtkeypad = KEYPAD3;
  2696.                 nvtaltcursor = '[';
  2697.                 vtkpbutset(kpdial, item_id);
  2698.                 DrawPicture(keypic[nvtkeypad - 1], &picrect);
  2699.                 break;
  2700.             }
  2701.             case KD_SWITCHKEY: {
  2702.                 okeypadswitch = !okeypadswitch;
  2703.                 GetDItem(kpdial, item_id, &type, &hitem, &rect);
  2704.                 SetCtlValue(hitem, okeypadswitch ? 1 : 0);
  2705.                 break;
  2706.             }
  2707.             default: {
  2708.                 break;
  2709.             }
  2710.         }
  2711.     }
  2712. }
  2713.  
  2714.  
  2715. /* set the button selected and reset the others */
  2716.  
  2717. vtkpbutset(dlog, itemid)
  2718. DialogPtr dlog;
  2719. short itemid;
  2720. {
  2721.     short    type;
  2722.     Rect rect;
  2723.     Handle hitem;
  2724.  
  2725.     GetDItem(dlog, KD_NORMKEY, &type, &hitem, &rect);
  2726.     SetCtlValue(hitem, itemid == KD_NORMKEY ? 1 : 0);
  2727.     GetDItem(dlog, KD_KEYPAD1, &type, &hitem, &rect);
  2728.     SetCtlValue(hitem, itemid == KD_KEYPAD1 ? 1 : 0);
  2729.     GetDItem(dlog, KD_KEYPAD2, &type, &hitem, &rect);
  2730.     SetCtlValue(hitem, itemid == KD_KEYPAD2 ? 1 : 0);
  2731.     GetDItem(dlog, KD_KEYPAD3, &type, &hitem, &rect);
  2732.     SetCtlValue(hitem, itemid == KD_KEYPAD3 ? 1 : 0);
  2733. }
  2734.  
  2735.  
  2736. radbuthilite(rectp, state)
  2737. Rect * rectp;
  2738. int state;
  2739. {
  2740.     rectp->top += 5;
  2741.     rectp->bottom -= 5;
  2742.     rectp->left += 5;
  2743.     rectp->right =  rectp->left + (rectp->bottom - rectp->top);
  2744.         /* we're just assuming the button position from the 
  2745.             control top/left/bottom position */
  2746.     FillOval(rectp, state ? black : white);
  2747. }
  2748.  
  2749.  
  2750. #define DTEXTTITLE    3
  2751. #define DTEXTSTRING    4
  2752.  
  2753. /* get a string of text from the user */
  2754.  
  2755. querytext(title, dest)
  2756. char * title;
  2757. unsigned char * dest;
  2758. {
  2759.     short item;
  2760.     DialogPtr dptr;
  2761.     GrafPtr oport;
  2762.     short type;
  2763.     Rect rect;
  2764.     Handle hitem;
  2765.     
  2766.     /* some connection has been attempted, get user's OK */
  2767.     GetPort(&oport);
  2768.     chkbackground();
  2769.  
  2770.     if ( (dptr = GetNewDialog(DGETTEXT, (Ptr) NULL, (WindowPtr) -1)) == NULL)  {
  2771.             return;
  2772.     }
  2773.  
  2774.     emwdeactivate();
  2775.     SetPort(dptr);
  2776.     centerwind(dptr);
  2777.     
  2778.     ctop(title);
  2779.     GetDItem(dptr, DTEXTTITLE, &type, &hitem, &rect);
  2780.     SetIText(hitem, title);
  2781.     ptoc(title);
  2782.     
  2783.     if (*dest != '\000') {
  2784.         /* if there was a find already performed use the previous string */
  2785.         ctop(dest);
  2786.         GetDItem(dptr, DTEXTSTRING, &type, &hitem, &rect);
  2787.         SetIText(hitem, dest);
  2788.         SelIText(dptr, DTEXTSTRING, 0, 1000);
  2789.         ptoc(dest);
  2790.     }
  2791.     /* hilite "OK" key */
  2792.     GetDItem(dptr, OKB, &type, &hitem, &rect);
  2793.     buthilite(&rect);
  2794.  
  2795.     TEFromScrap();
  2796.  
  2797.     modaldialog = TRUE;
  2798.     do {
  2799.         ModalDialog( (ProcPtr) alfilter, &item);
  2800.     }
  2801.     while (! (item == OKB || item == CANB));
  2802.  
  2803.     modaldialog = FALSE;
  2804.     ZeroScrap();
  2805.     TEToScrap();
  2806.         /* copy the TE scrap to the Scrap */
  2807.  
  2808.     if (item == CANB) {
  2809.         DisposDialog(dptr);
  2810.         SetPort(oport);
  2811.         return(TRUE);
  2812.     }
  2813.     /* set the string array to the string the user entered... */
  2814.     GetDItem(dptr, DTEXTSTRING, &type, &hitem, &rect);
  2815.     GetIText(hitem, dest);
  2816.     ptoc(dest);
  2817.  
  2818.     DisposDialog(dptr);
  2819.     SetPort(oport);
  2820.     return(FALSE);
  2821. }
  2822.  
  2823. /* ask the user whether an open serial session should be closed automatically
  2824.     when a new one is opened; returns TRUE if close desired */
  2825.  
  2826. queryserclose(twp)
  2827. struct winds * twp;
  2828. {
  2829.     short item;
  2830.     DialogPtr dptr;
  2831.     GrafPtr oport;
  2832.     short type;
  2833.     Rect rect;
  2834.     Handle hitem;
  2835.     
  2836.     /* some connection has been attempted, get user's OK */
  2837.     GetPort(&oport);
  2838.     chkbackground();
  2839.     HLock(twp->hhostname);
  2840.     ParamText(*twp->hhostname, "\P", "\P", "\P");
  2841.     HUnlock(twp->hhostname);
  2842.     if ( (dptr = GetNewDialog(DSERCLOSE, (Ptr) NULL, (WindowPtr) -1))
  2843.             != NULL)  {
  2844.  
  2845.         emwdeactivate();
  2846.         SetPort(dptr);
  2847.         centerwind(dptr);
  2848.         
  2849.         /* hilite "OK" key */
  2850.         GetDItem(dptr, QUITOK, &type, &hitem, &rect);
  2851.         buthilite(&rect);
  2852.  
  2853.         modaldialog = TRUE;
  2854.         do {
  2855.             ModalDialog( (ProcPtr) alfilter, &item);
  2856.         }
  2857.         while (item == 0);
  2858.  
  2859.         DisposDialog(dptr);
  2860.         SetPort(oport);
  2861.         modaldialog = FALSE;
  2862.         if (item == QUITCANCEL) {
  2863.             return(FALSE);
  2864.         }
  2865.     }
  2866.     return(TRUE);
  2867. }